mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
RunContext refactor + sync updates
This commit is contained in:
parent
c7cddb72c2
commit
d3cc11659a
79 changed files with 1415 additions and 626 deletions
|
|
@ -1,15 +1,20 @@
|
|||
//! Encoding and decoding utilities for Windows-invalid filename characters.
|
||||
//! Encoding and decoding utilities for special filename characters.
|
||||
//!
|
||||
//! Windows does not allow the following characters in file names:
|
||||
//! < > : " / \ | ? *
|
||||
//! This module encodes characters that are problematic in file names:
|
||||
//! - Windows-invalid characters: < > : " / \ | ? *
|
||||
//! - Periods (.) to prevent conflicts with file extension parsing
|
||||
//! - Leading/trailing spaces
|
||||
//! - Literal percent signs (%) to allow round-tripping
|
||||
//!
|
||||
//! Windows also does not allow leading/trailing spaces in file names.
|
||||
//!
|
||||
//! This module provides functions to encode these characters using a %NAME%
|
||||
//! format (e.g., `<` becomes `%LT%`) and decode them back.
|
||||
//! Characters are encoded using a %NAME% format (e.g., `<` becomes `%LT%`,
|
||||
//! `.` becomes `%DOT%`). Literal `%` is escaped as `%%` (like printf).
|
||||
|
||||
/// Mapping of Windows-invalid characters to their encoded representations.
|
||||
use std::collections::HashMap;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
/// Mapping of special characters to their encoded representations.
|
||||
const CHAR_ENCODINGS: &[(&str, &str)] = &[
|
||||
(".", "%DOT%"),
|
||||
("<", "%LT%"),
|
||||
(">", "%GT%"),
|
||||
(":", "%COLON%"),
|
||||
|
|
@ -21,13 +26,27 @@ const CHAR_ENCODINGS: &[(&str, &str)] = &[
|
|||
("*", "%STAR%"),
|
||||
];
|
||||
|
||||
/// Returns a map from encoded pattern (e.g., "DOT") to decoded char (e.g., ".").
|
||||
fn get_decode_map() -> &'static HashMap<&'static str, &'static str> {
|
||||
static DECODE_MAP: OnceLock<HashMap<&'static str, &'static str>> = OnceLock::new();
|
||||
DECODE_MAP.get_or_init(|| {
|
||||
let mut map = HashMap::new();
|
||||
for (char, encoded) in CHAR_ENCODINGS {
|
||||
// Strip the leading and trailing % from the pattern
|
||||
let pattern = &encoded[1..encoded.len() - 1];
|
||||
map.insert(pattern, *char);
|
||||
}
|
||||
map
|
||||
})
|
||||
}
|
||||
|
||||
const SPACE_ENCODING: &str = "%SPACE%";
|
||||
|
||||
/// Encodes Windows-invalid characters in a file name.
|
||||
/// Encodes special characters in a file name.
|
||||
///
|
||||
/// This replaces characters like `<`, `>`, `:`, `"`, `/`, `\`, `|`, `?`, `*`
|
||||
/// with their encoded representations like `%LT%`, `%GT%`, etc.
|
||||
/// Leading and trailing spaces are encoded as `%SPACE%`.
|
||||
/// This replaces characters like `.`, `<`, `>`, `:`, `"`, `/`, `\`, `|`, `?`, `*`
|
||||
/// with their encoded representations like `%DOT%`, `%LT%`, `%GT%`, etc.
|
||||
/// Literal `%` is escaped as `%%`. Leading and trailing spaces are encoded as `%SPACE%`.
|
||||
pub fn encode_path_name(name: &str) -> String {
|
||||
// Count leading and trailing spaces first (before any modifications)
|
||||
let leading_spaces = name.len() - name.trim_start_matches(' ').len();
|
||||
|
|
@ -36,8 +55,10 @@ pub fn encode_path_name(name: &str) -> String {
|
|||
// Get the middle part (without leading/trailing spaces)
|
||||
let middle = &name[leading_spaces..name.len() - trailing_spaces];
|
||||
|
||||
// Encode invalid characters in the middle part
|
||||
let mut encoded_middle = middle.to_string();
|
||||
// First: escape % as %% (before adding new % signs from encodings)
|
||||
let mut encoded_middle = middle.replace('%', "%%");
|
||||
|
||||
// Then: encode special characters
|
||||
for (char, encoded) in CHAR_ENCODINGS {
|
||||
encoded_middle = encoded_middle.replace(char, encoded);
|
||||
}
|
||||
|
|
@ -49,11 +70,13 @@ pub fn encode_path_name(name: &str) -> String {
|
|||
format!("{}{}{}", encoded_prefix, encoded_middle, encoded_suffix)
|
||||
}
|
||||
|
||||
/// Decodes encoded Windows-invalid characters back to their original form.
|
||||
/// Decodes encoded special characters back to their original form.
|
||||
///
|
||||
/// This replaces encoded representations like `%LT%`, `%GT%`, etc. back
|
||||
/// to their original characters `<`, `>`, etc.
|
||||
/// `%SPACE%` at the start/end is decoded back to spaces.
|
||||
/// This replaces encoded representations like `%DOT%`, `%LT%`, `%GT%`, etc.
|
||||
/// back to their original characters `.`, `<`, `>`, etc.
|
||||
/// `%%` is decoded to literal `%`. `%SPACE%` at the start/end is decoded back to spaces.
|
||||
///
|
||||
/// Uses a proper left-to-right parser to correctly handle `%%` escaping.
|
||||
pub fn decode_path_name(name: &str) -> String {
|
||||
let mut result = name.to_string();
|
||||
|
||||
|
|
@ -71,15 +94,83 @@ pub fn decode_path_name(name: &str) -> String {
|
|||
result = result[..result.len() - SPACE_ENCODING.len()].to_string();
|
||||
}
|
||||
|
||||
// Decode invalid characters in the middle
|
||||
for (char, encoded) in CHAR_ENCODINGS {
|
||||
result = result.replace(encoded, char);
|
||||
}
|
||||
// Parse and decode the middle part
|
||||
let decoded_middle = decode_patterns(&result);
|
||||
|
||||
// Rebuild with actual spaces
|
||||
let prefix = " ".repeat(leading_spaces);
|
||||
let suffix = " ".repeat(trailing_spaces);
|
||||
format!("{}{}{}", prefix, result, suffix)
|
||||
format!("{}{}{}", prefix, decoded_middle, suffix)
|
||||
}
|
||||
|
||||
/// Parses an encoded string left-to-right, properly handling `%%` escapes and `%NAME%` patterns.
|
||||
fn decode_patterns(input: &str) -> String {
|
||||
let decode_map = get_decode_map();
|
||||
let chars: Vec<char> = input.chars().collect();
|
||||
let mut output = String::with_capacity(input.len());
|
||||
let mut i = 0;
|
||||
|
||||
while i < chars.len() {
|
||||
if chars[i] == '%' {
|
||||
// Check for %% (escaped percent)
|
||||
if i + 1 < chars.len() && chars[i + 1] == '%' {
|
||||
output.push('%');
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try to match a %NAME% pattern
|
||||
if let Some((decoded, consumed)) = try_decode_pattern(&chars, i, decode_map) {
|
||||
output.push_str(&decoded);
|
||||
i += consumed;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Regular character, just copy it
|
||||
output.push(chars[i]);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
/// Tries to decode a %NAME% pattern starting at position `start`.
|
||||
/// Returns Some((decoded_string, chars_consumed)) if successful, None otherwise.
|
||||
fn try_decode_pattern(
|
||||
chars: &[char],
|
||||
start: usize,
|
||||
decode_map: &HashMap<&str, &str>,
|
||||
) -> Option<(String, usize)> {
|
||||
// Must start with %
|
||||
if chars.get(start) != Some(&'%') {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Find the closing %
|
||||
let mut end = start + 1;
|
||||
while end < chars.len() && chars[end] != '%' {
|
||||
// Pattern names are uppercase letters only
|
||||
if !chars[end].is_ascii_uppercase() {
|
||||
return None;
|
||||
}
|
||||
end += 1;
|
||||
}
|
||||
|
||||
// Must have found a closing %
|
||||
if end >= chars.len() || chars[end] != '%' {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Extract the pattern name (without the % delimiters)
|
||||
let pattern_name: String = chars[start + 1..end].iter().collect();
|
||||
|
||||
// Look up the pattern
|
||||
if let Some(&decoded) = decode_map.get(pattern_name.as_str()) {
|
||||
Some((decoded.to_string(), end - start + 1))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -88,15 +179,15 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_encode_all_chars() {
|
||||
let input = r#"<>:"/\|?*"#;
|
||||
let expected = "%LT%%GT%%COLON%%QUOTE%%SLASH%%BACKSLASH%%PIPE%%QUESTION%%STAR%";
|
||||
let input = r#".<>:"/\|?*"#;
|
||||
let expected = "%DOT%%LT%%GT%%COLON%%QUOTE%%SLASH%%BACKSLASH%%PIPE%%QUESTION%%STAR%";
|
||||
assert_eq!(encode_path_name(input), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decode_all_chars() {
|
||||
let input = "%LT%%GT%%COLON%%QUOTE%%SLASH%%BACKSLASH%%PIPE%%QUESTION%%STAR%";
|
||||
let expected = r#"<>:"/\|?*"#;
|
||||
let input = "%DOT%%LT%%GT%%COLON%%QUOTE%%SLASH%%BACKSLASH%%PIPE%%QUESTION%%STAR%";
|
||||
let expected = r#".<>:"/\|?*"#;
|
||||
assert_eq!(decode_path_name(input), expected);
|
||||
}
|
||||
|
||||
|
|
@ -154,4 +245,67 @@ mod tests {
|
|||
let decoded = decode_path_name(&encoded);
|
||||
assert_eq!(decoded, original);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_encode_period() {
|
||||
let input = "My.Script";
|
||||
let expected = "My%DOT%Script";
|
||||
assert_eq!(encode_path_name(input), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decode_period() {
|
||||
let input = "My%DOT%Script";
|
||||
let expected = "My.Script";
|
||||
assert_eq!(decode_path_name(input), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_roundtrip_with_period() {
|
||||
let original = "My.Module.Name";
|
||||
let encoded = encode_path_name(original);
|
||||
let decoded = decode_path_name(&encoded);
|
||||
assert_eq!(decoded, original);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_encode_percent() {
|
||||
let input = "My%Thing";
|
||||
let expected = "My%%Thing";
|
||||
assert_eq!(encode_path_name(input), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decode_percent() {
|
||||
let input = "My%%Thing";
|
||||
let expected = "My%Thing";
|
||||
assert_eq!(decode_path_name(input), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_roundtrip_with_percent() {
|
||||
let original = "My%Thing";
|
||||
let encoded = encode_path_name(original);
|
||||
let decoded = decode_path_name(&encoded);
|
||||
assert_eq!(decoded, original);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_percent_encoding_pattern_roundtrip() {
|
||||
// This tests that a name containing what looks like an encoding pattern
|
||||
// round-trips correctly and doesn't get incorrectly decoded
|
||||
let original = "My%DOT%Thing";
|
||||
let encoded = encode_path_name(original);
|
||||
assert_eq!(encoded, "My%%DOT%%Thing");
|
||||
let decoded = decode_path_name(&encoded);
|
||||
assert_eq!(decoded, original);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_combined_period_and_percent() {
|
||||
let original = "My.%Thing.Other";
|
||||
let encoded = encode_path_name(original);
|
||||
let decoded = decode_path_name(&encoded);
|
||||
assert_eq!(decoded, original);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,12 +110,6 @@ pub struct Project {
|
|||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub serve_address: Option<IpAddr>,
|
||||
|
||||
/// Determines if Rojo should emit scripts with the appropriate `RunContext`
|
||||
/// for `*.client.lua` and `*.server.lua` files in the project instead of
|
||||
/// using `Script` and `LocalScript` Instances.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub emit_legacy_scripts: Option<bool>,
|
||||
|
||||
/// A list of globs, relative to the folder the project file is in, that
|
||||
/// match files that should be excluded if Rojo encounters them.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
|
|
@ -573,7 +567,6 @@ mod test {
|
|||
"$path": "src", // Comment after value
|
||||
},
|
||||
"servePort": 34567,
|
||||
"emitLegacyScripts": false,
|
||||
// Test glob parsing with comments
|
||||
"globIgnorePaths": [
|
||||
"**/*.spec.lua", // Ignore test files
|
||||
|
|
@ -601,7 +594,6 @@ mod test {
|
|||
// Verify the parsed values
|
||||
assert_eq!(project.name, Some("TestProject".to_string()));
|
||||
assert_eq!(project.serve_port, Some(34567));
|
||||
assert_eq!(project.emit_legacy_scripts, Some(false));
|
||||
|
||||
// Verify glob_ignore_paths were parsed correctly
|
||||
assert_eq!(project.glob_ignore_paths.len(), 2);
|
||||
|
|
|
|||
|
|
@ -110,10 +110,9 @@ impl ServeSession {
|
|||
.syncback_rules
|
||||
.as_ref()
|
||||
.map(|rules| rules.encode_windows_invalid_chars())
|
||||
.unwrap_or(false);
|
||||
.unwrap_or(true);
|
||||
|
||||
let mut instance_context =
|
||||
InstanceContext::with_emit_legacy_scripts(root_project.emit_legacy_scripts);
|
||||
let mut instance_context = InstanceContext::new();
|
||||
instance_context.set_decode_windows_invalid_chars(decode_windows_invalid_chars);
|
||||
|
||||
log::trace!("Generating snapshot of instances from VFS");
|
||||
|
|
|
|||
|
|
@ -8,11 +8,7 @@ use anyhow::Context;
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
glob::Glob,
|
||||
path_serializer,
|
||||
project::ProjectNode,
|
||||
snapshot_middleware::{emit_legacy_scripts_default, Middleware},
|
||||
RojoRef,
|
||||
glob::Glob, path_serializer, project::ProjectNode, snapshot_middleware::Middleware, RojoRef,
|
||||
};
|
||||
|
||||
/// Rojo-specific metadata that can be associated with an instance or a snapshot
|
||||
|
|
@ -142,32 +138,26 @@ impl Default for InstanceMetadata {
|
|||
pub struct InstanceContext {
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub path_ignore_rules: Arc<Vec<PathIgnoreRule>>,
|
||||
pub emit_legacy_scripts: bool,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub sync_rules: Vec<SyncRule>,
|
||||
/// Whether to decode Windows-invalid characters in file names.
|
||||
/// Characters like `%LT%`, `%GT%`, `%COLON%`, etc. will be decoded
|
||||
/// back to `<`, `>`, `:`, etc. in instance names sent to the plugin.
|
||||
#[serde(default)]
|
||||
/// Whether to decode special characters in file names.
|
||||
/// Characters like `%DOT%`, `%LT%`, `%GT%`, `%COLON%`, etc. will be decoded
|
||||
/// back to `.`, `<`, `>`, `:`, etc. in instance names sent to the plugin.
|
||||
/// Defaults to true.
|
||||
#[serde(default = "decode_windows_invalid_chars_default")]
|
||||
pub decode_windows_invalid_chars: bool,
|
||||
}
|
||||
|
||||
fn decode_windows_invalid_chars_default() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
impl InstanceContext {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
path_ignore_rules: Arc::new(Vec::new()),
|
||||
emit_legacy_scripts: emit_legacy_scripts_default().unwrap(),
|
||||
sync_rules: Vec::new(),
|
||||
decode_windows_invalid_chars: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_emit_legacy_scripts(emit_legacy_scripts: Option<bool>) -> Self {
|
||||
Self {
|
||||
emit_legacy_scripts: emit_legacy_scripts
|
||||
.or_else(emit_legacy_scripts_default)
|
||||
.unwrap(),
|
||||
..Self::new()
|
||||
decode_windows_invalid_chars: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -206,10 +196,6 @@ impl InstanceContext {
|
|||
self.sync_rules.clear();
|
||||
}
|
||||
|
||||
pub fn set_emit_legacy_scripts(&mut self, emit_legacy_scripts: bool) {
|
||||
self.emit_legacy_scripts = emit_legacy_scripts;
|
||||
}
|
||||
|
||||
/// Returns the middleware specified by the first sync rule that
|
||||
/// matches the provided path. This does not handle default syncing rules.
|
||||
pub fn get_user_sync_rule(&self, path: &Path) -> Option<&SyncRule> {
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@ metadata:
|
|||
ignore_unknown_instances: false
|
||||
relevant_paths: []
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
ignore_unknown_instances: false
|
||||
relevant_paths: []
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@ metadata:
|
|||
ignore_unknown_instances: false
|
||||
relevant_paths: []
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
ignore_unknown_instances: false
|
||||
relevant_paths: []
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ added_instances:
|
|||
ignore_unknown_instances: false
|
||||
relevant_paths: []
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -383,7 +383,7 @@ Ack,Ack!,,An exclamation of despair,¡Ay!"#,
|
|||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_csv_init(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(true)),
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/root/init.csv"),
|
||||
"root",
|
||||
|
|
@ -421,7 +421,7 @@ Ack,Ack!,,An exclamation of despair,¡Ay!"#,
|
|||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_csv_init(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(true)),
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/root/init.csv"),
|
||||
"root",
|
||||
|
|
|
|||
|
|
@ -21,14 +21,12 @@ use super::{
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum ScriptType {
|
||||
Server,
|
||||
Client,
|
||||
Module,
|
||||
Plugin,
|
||||
LegacyServer,
|
||||
LegacyClient,
|
||||
RunContextServer,
|
||||
RunContextClient,
|
||||
Server, // Script + RunContext.Server
|
||||
Client, // Script + RunContext.Client
|
||||
Module, // ModuleScript
|
||||
Plugin, // Script + RunContext.Plugin
|
||||
Legacy, // Script + RunContext.Legacy
|
||||
Local, // LocalScript
|
||||
}
|
||||
|
||||
/// Core routine for turning Lua files into snapshots.
|
||||
|
|
@ -47,26 +45,12 @@ pub fn snapshot_lua(
|
|||
.items;
|
||||
|
||||
let (class_name, run_context) = match script_type {
|
||||
ScriptType::Server => {
|
||||
if context.emit_legacy_scripts {
|
||||
("Script", run_context_enums.get("Legacy"))
|
||||
} else {
|
||||
("Script", run_context_enums.get("Server"))
|
||||
}
|
||||
}
|
||||
ScriptType::Client => {
|
||||
if context.emit_legacy_scripts {
|
||||
("LocalScript", None)
|
||||
} else {
|
||||
("Script", run_context_enums.get("Client"))
|
||||
}
|
||||
}
|
||||
ScriptType::Server => ("Script", run_context_enums.get("Server")),
|
||||
ScriptType::Client => ("Script", run_context_enums.get("Client")),
|
||||
ScriptType::Module => ("ModuleScript", None),
|
||||
ScriptType::Plugin => ("Script", run_context_enums.get("Plugin")),
|
||||
ScriptType::LegacyServer => ("Script", run_context_enums.get("Legacy")),
|
||||
ScriptType::LegacyClient => ("LocalScript", None),
|
||||
ScriptType::RunContextServer => ("Script", run_context_enums.get("Server")),
|
||||
ScriptType::RunContextClient => ("Script", run_context_enums.get("Client")),
|
||||
ScriptType::Legacy => ("Script", run_context_enums.get("Legacy")),
|
||||
ScriptType::Local => ("LocalScript", None),
|
||||
};
|
||||
|
||||
let contents = vfs.read_to_string_lf_normalized(path)?;
|
||||
|
|
@ -101,8 +85,9 @@ pub fn snapshot_lua(
|
|||
/// Attempts to snapshot an 'init' Lua script contained inside of a folder with
|
||||
/// the given name.
|
||||
///
|
||||
/// Scripts named `init.lua`, `init.server.lua`, or `init.client.lua` usurp
|
||||
/// their parents, which acts similarly to `__init__.py` from the Python world.
|
||||
/// Scripts named `init.lua`, `init.server.lua`, `init.client.lua`, `init.local.lua`,
|
||||
/// `init.legacy.lua`, or `init.plugin.lua` usurp their parents, which acts similarly
|
||||
/// to `__init__.py` from the Python world.
|
||||
pub fn snapshot_lua_init(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
|
|
@ -115,9 +100,8 @@ pub fn snapshot_lua_init(
|
|||
|
||||
if dir_snapshot.class_name != "Folder" {
|
||||
anyhow::bail!(
|
||||
"init.lua, init.server.lua, and init.client.lua can \
|
||||
only be used if the instance produced by the containing \
|
||||
directory would be a Folder.\n\
|
||||
"init scripts can only be used if the instance produced by the \
|
||||
containing directory would be a Folder.\n\
|
||||
\n\
|
||||
The directory {} turned into an instance of class {}.",
|
||||
folder_path.display(),
|
||||
|
|
@ -177,6 +161,8 @@ pub fn syncback_lua<'sync>(
|
|||
.strip_suffix(".server")
|
||||
.or_else(|| file_stem.strip_suffix(".client"))
|
||||
.or_else(|| file_stem.strip_suffix(".plugin"))
|
||||
.or_else(|| file_stem.strip_suffix(".local"))
|
||||
.or_else(|| file_stem.strip_suffix(".legacy"))
|
||||
.unwrap_or(file_stem);
|
||||
let meta_name = if meta_name.is_empty() {
|
||||
if snapshot.encode_windows_invalid_chars() {
|
||||
|
|
@ -211,7 +197,9 @@ pub fn syncback_lua_init<'sync>(
|
|||
ScriptType::Server => "init.server.luau",
|
||||
ScriptType::Client => "init.client.luau",
|
||||
ScriptType::Module => "init.luau",
|
||||
_ => anyhow::bail!("syncback is not yet implemented for {script_type:?}"),
|
||||
ScriptType::Plugin => "init.plugin.luau",
|
||||
ScriptType::Legacy => "init.legacy.luau",
|
||||
ScriptType::Local => "init.local.luau",
|
||||
});
|
||||
|
||||
let contents = if let Some(Variant::String(source)) = new_inst.properties.get(&ustr("Source")) {
|
||||
|
|
@ -248,7 +236,7 @@ mod test {
|
|||
use memofs::{InMemoryFs, VfsSnapshot};
|
||||
|
||||
#[test]
|
||||
fn class_module_from_vfs() {
|
||||
fn module_from_vfs() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/foo.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
|
|
@ -256,7 +244,7 @@ mod test {
|
|||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(true)),
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/foo.lua"),
|
||||
"foo",
|
||||
|
|
@ -271,30 +259,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn runcontext_module_from_vfs() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/foo.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
|
||||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(false)),
|
||||
&vfs,
|
||||
Path::new("/foo.lua"),
|
||||
"foo",
|
||||
ScriptType::Module,
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
insta::with_settings!({ sort_maps => true }, {
|
||||
insta::assert_yaml_snapshot!(instance_snapshot);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plugin_module_from_vfs() {
|
||||
fn plugin_from_vfs() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/foo.plugin.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
|
|
@ -302,7 +267,7 @@ mod test {
|
|||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(false)),
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/foo.plugin.lua"),
|
||||
"foo",
|
||||
|
|
@ -317,7 +282,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn class_server_from_vfs() {
|
||||
fn server_from_vfs() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/foo.server.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
|
|
@ -325,7 +290,7 @@ mod test {
|
|||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(true)),
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/foo.server.lua"),
|
||||
"foo",
|
||||
|
|
@ -340,30 +305,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn runcontext_server_from_vfs() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/foo.server.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
|
||||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(false)),
|
||||
&vfs,
|
||||
Path::new("/foo.server.lua"),
|
||||
"foo",
|
||||
ScriptType::Server,
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
insta::with_settings!({ sort_maps => true }, {
|
||||
insta::assert_yaml_snapshot!(instance_snapshot);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn class_client_from_vfs() {
|
||||
fn client_from_vfs() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/foo.client.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
|
|
@ -371,7 +313,7 @@ mod test {
|
|||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(true)),
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/foo.client.lua"),
|
||||
"foo",
|
||||
|
|
@ -386,19 +328,42 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn runcontext_client_from_vfs() {
|
||||
fn local_from_vfs() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/foo.client.lua", VfsSnapshot::file("Hello there!"))
|
||||
imfs.load_snapshot("/foo.local.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
|
||||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(false)),
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/foo.client.lua"),
|
||||
Path::new("/foo.local.lua"),
|
||||
"foo",
|
||||
ScriptType::Client,
|
||||
ScriptType::Local,
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
insta::with_settings!({ sort_maps => true }, {
|
||||
insta::assert_yaml_snapshot!(instance_snapshot);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_from_vfs() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/foo.legacy.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
|
||||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/foo.legacy.lua"),
|
||||
"foo",
|
||||
ScriptType::Legacy,
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
|
@ -420,7 +385,7 @@ mod test {
|
|||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua_init(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(true)),
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/root/init.lua"),
|
||||
"root",
|
||||
|
|
@ -452,7 +417,7 @@ mod test {
|
|||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua_init(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(true)),
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/root/init.lua"),
|
||||
"root",
|
||||
|
|
@ -467,7 +432,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn class_module_with_meta() {
|
||||
fn module_with_meta() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/foo.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
|
|
@ -486,7 +451,7 @@ mod test {
|
|||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(true)),
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/foo.lua"),
|
||||
"foo",
|
||||
|
|
@ -501,41 +466,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn runcontext_module_with_meta() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/foo.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
imfs.load_snapshot(
|
||||
"/foo.meta.json",
|
||||
VfsSnapshot::file(
|
||||
r#"
|
||||
{
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
"#,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(false)),
|
||||
&vfs,
|
||||
Path::new("/foo.lua"),
|
||||
"foo",
|
||||
ScriptType::Module,
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
insta::with_settings!({ sort_maps => true }, {
|
||||
insta::assert_yaml_snapshot!(instance_snapshot);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn class_script_with_meta() {
|
||||
fn server_with_meta() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/foo.server.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
|
|
@ -554,7 +485,7 @@ mod test {
|
|||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(true)),
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/foo.server.lua"),
|
||||
"foo",
|
||||
|
|
@ -569,41 +500,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn runcontext_script_with_meta() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/foo.server.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
imfs.load_snapshot(
|
||||
"/foo.meta.json",
|
||||
VfsSnapshot::file(
|
||||
r#"
|
||||
{
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
"#,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(false)),
|
||||
&vfs,
|
||||
Path::new("/foo.server.lua"),
|
||||
"foo",
|
||||
ScriptType::Server,
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
insta::with_settings!({ sort_maps => true }, {
|
||||
insta::assert_yaml_snapshot!(instance_snapshot);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn class_script_disabled() {
|
||||
fn server_disabled() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/bar.server.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
|
|
@ -624,43 +521,7 @@ mod test {
|
|||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(true)),
|
||||
&vfs,
|
||||
Path::new("/bar.server.lua"),
|
||||
"bar",
|
||||
ScriptType::Server,
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
insta::with_settings!({ sort_maps => true }, {
|
||||
insta::assert_yaml_snapshot!(instance_snapshot);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runcontext_script_disabled() {
|
||||
let mut imfs = InMemoryFs::new();
|
||||
imfs.load_snapshot("/bar.server.lua", VfsSnapshot::file("Hello there!"))
|
||||
.unwrap();
|
||||
imfs.load_snapshot(
|
||||
"/bar.meta.json",
|
||||
VfsSnapshot::file(
|
||||
r#"
|
||||
{
|
||||
"properties": {
|
||||
"Disabled": true
|
||||
}
|
||||
}
|
||||
"#,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let vfs = Vfs::new(imfs);
|
||||
|
||||
let instance_snapshot = snapshot_lua(
|
||||
&InstanceContext::with_emit_legacy_scripts(Some(false)),
|
||||
&InstanceContext::new(),
|
||||
&vfs,
|
||||
Path::new("/bar.server.lua"),
|
||||
"bar",
|
||||
|
|
|
|||
|
|
@ -55,13 +55,14 @@ impl AdjacentMetadata {
|
|||
// Use the file stem from the actual path (which has encoded chars)
|
||||
// rather than the decoded name, so meta files are found correctly
|
||||
// when encodeWindowsInvalidChars is enabled.
|
||||
// Strip known script type suffixes (.server, .client, .plugin) to get
|
||||
// the base name for the meta file.
|
||||
// Strip known script type suffixes to get the base name for the meta file.
|
||||
let file_stem = path.file_stem().and_then(|s| s.to_str()).unwrap_or("");
|
||||
let base_name = file_stem
|
||||
.strip_suffix(".server")
|
||||
.or_else(|| file_stem.strip_suffix(".client"))
|
||||
.or_else(|| file_stem.strip_suffix(".plugin"))
|
||||
.or_else(|| file_stem.strip_suffix(".local"))
|
||||
.or_else(|| file_stem.strip_suffix(".legacy"))
|
||||
.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"));
|
||||
|
|
|
|||
|
|
@ -53,10 +53,7 @@ use self::{
|
|||
yaml::snapshot_yaml,
|
||||
};
|
||||
|
||||
pub use self::{
|
||||
lua::ScriptType, project::snapshot_project_node, util::emit_legacy_scripts_default,
|
||||
util::PathExt,
|
||||
};
|
||||
pub use self::{lua::ScriptType, project::snapshot_project_node, util::PathExt};
|
||||
|
||||
/// Returns an `InstanceSnapshot` for the provided path.
|
||||
/// This will inspect the path and find the appropriate middleware for it,
|
||||
|
|
@ -98,6 +95,7 @@ pub fn snapshot_from_vfs(
|
|||
// TODO: Is this even necessary anymore?
|
||||
match file_name {
|
||||
"init.server.luau" | "init.server.lua" | "init.client.luau" | "init.client.lua"
|
||||
| "init.local.luau" | "init.local.lua" | "init.legacy.luau" | "init.legacy.lua"
|
||||
| "init.luau" | "init.lua" | "init.csv" => return Ok(None),
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -131,6 +129,10 @@ fn get_dir_middleware<'path>(
|
|||
(Middleware::ServerScriptDir, "init.server.lua"),
|
||||
(Middleware::ClientScriptDir, "init.client.luau"),
|
||||
(Middleware::ClientScriptDir, "init.client.lua"),
|
||||
(Middleware::LocalScriptDir, "init.local.luau"),
|
||||
(Middleware::LocalScriptDir, "init.local.lua"),
|
||||
(Middleware::LegacyScriptDir, "init.legacy.luau"),
|
||||
(Middleware::LegacyScriptDir, "init.legacy.lua"),
|
||||
(Middleware::CsvDir, "init.csv"),
|
||||
]
|
||||
});
|
||||
|
|
@ -197,10 +199,8 @@ pub enum Middleware {
|
|||
ClientScript,
|
||||
ModuleScript,
|
||||
PluginScript,
|
||||
LegacyClientScript,
|
||||
LegacyServerScript,
|
||||
RunContextServerScript,
|
||||
RunContextClientScript,
|
||||
LocalScript,
|
||||
LegacyScript,
|
||||
Project,
|
||||
Rbxm,
|
||||
Rbxmx,
|
||||
|
|
@ -218,6 +218,10 @@ pub enum Middleware {
|
|||
#[serde(skip_deserializing)]
|
||||
ModuleScriptDir,
|
||||
#[serde(skip_deserializing)]
|
||||
LocalScriptDir,
|
||||
#[serde(skip_deserializing)]
|
||||
LegacyScriptDir,
|
||||
#[serde(skip_deserializing)]
|
||||
CsvDir,
|
||||
}
|
||||
|
||||
|
|
@ -239,18 +243,8 @@ impl Middleware {
|
|||
Self::ClientScript => snapshot_lua(context, vfs, path, name, ScriptType::Client),
|
||||
Self::ModuleScript => snapshot_lua(context, vfs, path, name, ScriptType::Module),
|
||||
Self::PluginScript => snapshot_lua(context, vfs, path, name, ScriptType::Plugin),
|
||||
Self::LegacyClientScript => {
|
||||
snapshot_lua(context, vfs, path, name, ScriptType::LegacyClient)
|
||||
}
|
||||
Self::LegacyServerScript => {
|
||||
snapshot_lua(context, vfs, path, name, ScriptType::LegacyServer)
|
||||
}
|
||||
Self::RunContextClientScript => {
|
||||
snapshot_lua(context, vfs, path, name, ScriptType::RunContextClient)
|
||||
}
|
||||
Self::RunContextServerScript => {
|
||||
snapshot_lua(context, vfs, path, name, ScriptType::RunContextServer)
|
||||
}
|
||||
Self::LocalScript => snapshot_lua(context, vfs, path, name, ScriptType::Local),
|
||||
Self::LegacyScript => snapshot_lua(context, vfs, path, name, ScriptType::Legacy),
|
||||
Self::Project => snapshot_project(context, vfs, path, name),
|
||||
Self::Rbxm => snapshot_rbxm(context, vfs, path, name),
|
||||
Self::Rbxmx => snapshot_rbxmx(context, vfs, path, name),
|
||||
|
|
@ -269,6 +263,10 @@ impl Middleware {
|
|||
Self::ModuleScriptDir => {
|
||||
snapshot_lua_init(context, vfs, path, name, ScriptType::Module)
|
||||
}
|
||||
Self::LocalScriptDir => snapshot_lua_init(context, vfs, path, name, ScriptType::Local),
|
||||
Self::LegacyScriptDir => {
|
||||
snapshot_lua_init(context, vfs, path, name, ScriptType::Legacy)
|
||||
}
|
||||
Self::CsvDir => snapshot_csv_init(context, vfs, path, name),
|
||||
};
|
||||
if let Ok(Some(ref mut snapshot)) = output {
|
||||
|
|
@ -299,6 +297,9 @@ impl Middleware {
|
|||
Middleware::ServerScript => syncback_lua(snapshot),
|
||||
Middleware::ClientScript => syncback_lua(snapshot),
|
||||
Middleware::ModuleScript => syncback_lua(snapshot),
|
||||
Middleware::PluginScript => syncback_lua(snapshot),
|
||||
Middleware::LocalScript => syncback_lua(snapshot),
|
||||
Middleware::LegacyScript => syncback_lua(snapshot),
|
||||
Middleware::Rbxm => syncback_rbxm(snapshot),
|
||||
Middleware::Rbxmx => syncback_rbxmx(snapshot),
|
||||
Middleware::Toml => anyhow::bail!("cannot syncback Toml middleware"),
|
||||
|
|
@ -309,15 +310,9 @@ impl Middleware {
|
|||
Middleware::ServerScriptDir => syncback_lua_init(ScriptType::Server, snapshot),
|
||||
Middleware::ClientScriptDir => syncback_lua_init(ScriptType::Client, snapshot),
|
||||
Middleware::ModuleScriptDir => syncback_lua_init(ScriptType::Module, snapshot),
|
||||
Middleware::LocalScriptDir => syncback_lua_init(ScriptType::Local, snapshot),
|
||||
Middleware::LegacyScriptDir => syncback_lua_init(ScriptType::Legacy, snapshot),
|
||||
Middleware::CsvDir => syncback_csv_init(snapshot),
|
||||
|
||||
Middleware::PluginScript
|
||||
| Middleware::LegacyServerScript
|
||||
| Middleware::LegacyClientScript
|
||||
| Middleware::RunContextServerScript
|
||||
| Middleware::RunContextClientScript => {
|
||||
anyhow::bail!("syncback is not implemented for {self:?} yet")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -330,6 +325,8 @@ impl Middleware {
|
|||
| Middleware::ServerScriptDir
|
||||
| Middleware::ClientScriptDir
|
||||
| Middleware::ModuleScriptDir
|
||||
| Middleware::LocalScriptDir
|
||||
| Middleware::LegacyScriptDir
|
||||
| Middleware::CsvDir
|
||||
)
|
||||
}
|
||||
|
|
@ -427,6 +424,10 @@ pub fn default_sync_rules() -> &'static [SyncRule] {
|
|||
sync_rule!("*.client.luau", ClientScript, ".client.luau"),
|
||||
sync_rule!("*.plugin.lua", PluginScript, ".plugin.lua"),
|
||||
sync_rule!("*.plugin.luau", PluginScript, ".plugin.luau"),
|
||||
sync_rule!("*.legacy.lua", LegacyScript, ".legacy.lua"),
|
||||
sync_rule!("*.legacy.luau", LegacyScript, ".legacy.luau"),
|
||||
sync_rule!("*.local.lua", LocalScript, ".local.lua"),
|
||||
sync_rule!("*.local.luau", LocalScript, ".local.luau"),
|
||||
sync_rule!("*.{lua,luau}", ModuleScript),
|
||||
sync_rule!("*.project.json", Project, ".project.json"),
|
||||
sync_rule!("*.project.jsonc", Project, ".project.jsonc"),
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ use crate::{
|
|||
RojoRef,
|
||||
};
|
||||
|
||||
use super::{emit_legacy_scripts_default, snapshot_from_vfs};
|
||||
use super::snapshot_from_vfs;
|
||||
|
||||
pub fn snapshot_project(
|
||||
context: &InstanceContext,
|
||||
|
|
@ -55,12 +55,6 @@ pub fn snapshot_project(
|
|||
|
||||
context.add_sync_rules(sync_rules);
|
||||
context.add_path_ignore_rules(rules);
|
||||
context.set_emit_legacy_scripts(
|
||||
project
|
||||
.emit_legacy_scripts
|
||||
.or_else(emit_legacy_scripts_default)
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
match snapshot_project_node(&context, path, project_name, &project.tree, vfs, None)? {
|
||||
Some(found_snapshot) => {
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ metadata:
|
|||
- /root/init.meta.jsonc
|
||||
- /root/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ metadata:
|
|||
- /root/init.meta.jsonc
|
||||
- /root/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: manually specified
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ metadata:
|
|||
- /foo/init.meta.jsonc
|
||||
- /foo/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ metadata:
|
|||
- /foo/init.meta.jsonc
|
||||
- /foo/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
@ -47,8 +46,7 @@ children:
|
|||
- /foo/Child/init.meta.jsonc
|
||||
- /foo/Child/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: dir
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: manually specified
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
relevant_paths:
|
||||
- /foo.model.json
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
@ -26,8 +25,7 @@ children:
|
|||
ignore_unknown_instances: false
|
||||
relevant_paths: []
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
relevant_paths:
|
||||
- /foo.model.json
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
@ -26,8 +25,7 @@ children:
|
|||
ignore_unknown_instances: false
|
||||
relevant_paths: []
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
---
|
||||
source: src/snapshot_middleware/lua.rs
|
||||
expression: instance_snapshot
|
||||
---
|
||||
snapshot_id: "00000000000000000000000000000000"
|
||||
metadata:
|
||||
ignore_unknown_instances: false
|
||||
instigating_source:
|
||||
Path: /bar.server.lua
|
||||
relevant_paths:
|
||||
- /bar.server.lua
|
||||
- /bar.meta.json
|
||||
- /bar.meta.jsonc
|
||||
- /bar.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
name: bar
|
||||
class_name: Script
|
||||
properties:
|
||||
Disabled:
|
||||
Bool: true
|
||||
RunContext:
|
||||
Enum: 0
|
||||
Source:
|
||||
String: Hello there!
|
||||
children: []
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
---
|
||||
source: src/snapshot_middleware/lua.rs
|
||||
expression: instance_snapshot
|
||||
---
|
||||
snapshot_id: "00000000000000000000000000000000"
|
||||
metadata:
|
||||
ignore_unknown_instances: true
|
||||
instigating_source:
|
||||
Path: /foo.server.lua
|
||||
relevant_paths:
|
||||
- /foo.server.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
name: foo
|
||||
class_name: Script
|
||||
properties:
|
||||
RunContext:
|
||||
Enum: 0
|
||||
Source:
|
||||
String: Hello there!
|
||||
children: []
|
||||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
@ -20,8 +20,7 @@ metadata:
|
|||
- /root/init.meta.jsonc
|
||||
- /root/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ metadata:
|
|||
- /root/init.meta.jsonc
|
||||
- /root/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: manually specified
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -6,15 +6,14 @@ snapshot_id: "00000000000000000000000000000000"
|
|||
metadata:
|
||||
ignore_unknown_instances: false
|
||||
instigating_source:
|
||||
Path: /foo.server.lua
|
||||
Path: /foo.legacy.lua
|
||||
relevant_paths:
|
||||
- /foo.server.lua
|
||||
- /foo.legacy.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
@ -6,15 +6,14 @@ snapshot_id: "00000000000000000000000000000000"
|
|||
metadata:
|
||||
ignore_unknown_instances: false
|
||||
instigating_source:
|
||||
Path: /foo.client.lua
|
||||
Path: /foo.local.lua
|
||||
relevant_paths:
|
||||
- /foo.client.lua
|
||||
- /foo.local.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
source: src/snapshot_middleware/lua.rs
|
||||
expression: instance_snapshot
|
||||
---
|
||||
snapshot_id: "00000000000000000000000000000000"
|
||||
metadata:
|
||||
ignore_unknown_instances: false
|
||||
instigating_source:
|
||||
Path: /foo.plugin.lua
|
||||
relevant_paths:
|
||||
- /foo.plugin.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
name: foo
|
||||
class_name: Script
|
||||
properties:
|
||||
RunContext:
|
||||
Enum: 3
|
||||
Source:
|
||||
String: Hello there!
|
||||
children: []
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
---
|
||||
source: src/snapshot_middleware/lua.rs
|
||||
expression: instance_snapshot
|
||||
---
|
||||
snapshot_id: "00000000000000000000000000000000"
|
||||
metadata:
|
||||
ignore_unknown_instances: false
|
||||
instigating_source:
|
||||
Path: /foo.lua
|
||||
relevant_paths:
|
||||
- /foo.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
name: foo
|
||||
class_name: ModuleScript
|
||||
properties:
|
||||
Source:
|
||||
String: Hello there!
|
||||
children: []
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
---
|
||||
source: src/snapshot_middleware/lua.rs
|
||||
expression: instance_snapshot
|
||||
---
|
||||
snapshot_id: "00000000000000000000000000000000"
|
||||
metadata:
|
||||
ignore_unknown_instances: true
|
||||
instigating_source:
|
||||
Path: /foo.lua
|
||||
relevant_paths:
|
||||
- /foo.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
name: foo
|
||||
class_name: ModuleScript
|
||||
properties:
|
||||
Source:
|
||||
String: Hello there!
|
||||
children: []
|
||||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /bar.meta.jsonc
|
||||
- /bar.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
- /foo/bar.meta.jsonc
|
||||
- /foo/bar.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: manually specified
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
- /foo/bar.meta.jsonc
|
||||
- /foo/bar.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: manually specified
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
- /foo/init.meta.jsonc
|
||||
- /foo/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: manually specified
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
- /foo/init.meta.jsonc
|
||||
- /foo/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: manually specified
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
relevant_paths:
|
||||
- /foo/default.project.json
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
relevant_paths:
|
||||
- /foo/hello.project.json
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ metadata:
|
|||
- /foo/other.project.json
|
||||
- /foo/default.project.json
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: project
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
relevant_paths:
|
||||
- /foo.project.json
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
@ -31,8 +30,7 @@ children:
|
|||
parent_class: Folder
|
||||
relevant_paths: []
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ metadata:
|
|||
- /foo/other.project.json
|
||||
- /foo/default.project.json
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: project
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ metadata:
|
|||
- /foo/other.project.json
|
||||
- /foo/default.project.json
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: project
|
||||
schema: ~
|
||||
|
|
@ -32,8 +31,7 @@ children:
|
|||
parent_class: Folder
|
||||
relevant_paths: []
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -14,8 +14,7 @@ metadata:
|
|||
- /foo/other.meta.json5
|
||||
- /foo/default.project.json
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: text
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
relevant_paths:
|
||||
- /foo.project.json
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ metadata:
|
|||
relevant_paths:
|
||||
- /foo.project.json
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- foo.meta.jsonc
|
||||
- foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: manually specified
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: manually specified
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: ~
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ metadata:
|
|||
- foo.meta.jsonc
|
||||
- foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
decode_windows_invalid_chars: true
|
||||
specified_id: manually specified
|
||||
middleware: ~
|
||||
schema: ~
|
||||
|
|
|
|||
|
|
@ -48,8 +48,3 @@ where
|
|||
.with_context(|| format!("Path does not have a parent: {}", path.display()))
|
||||
}
|
||||
}
|
||||
|
||||
// TEMP function until rojo 8.0, when it can be replaced with bool::default (aka false)
|
||||
pub fn emit_legacy_scripts_default() -> Option<bool> {
|
||||
Some(true)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,8 @@ pub fn extension_for_middleware(middleware: Middleware) -> &'static str {
|
|||
Middleware::ClientScript => "client.luau",
|
||||
Middleware::ModuleScript => "luau",
|
||||
Middleware::PluginScript => "plugin.luau",
|
||||
Middleware::LocalScript => "local.luau",
|
||||
Middleware::LegacyScript => "legacy.luau",
|
||||
Middleware::Project => "project.json5",
|
||||
Middleware::Rbxm => "rbxm",
|
||||
Middleware::Rbxmx => "rbxmx",
|
||||
|
|
@ -98,12 +100,6 @@ pub fn extension_for_middleware(middleware: Middleware) -> &'static str {
|
|||
Middleware::Text => "txt",
|
||||
Middleware::Yaml => "yml",
|
||||
|
||||
Middleware::LegacyServerScript
|
||||
| Middleware::LegacyClientScript
|
||||
| Middleware::RunContextServerScript
|
||||
| Middleware::RunContextClientScript => {
|
||||
todo!("syncback does not work on the middleware {middleware:?} yet")
|
||||
}
|
||||
// These are manually specified and not `_` to guard against future
|
||||
// middleware additions missing this function.
|
||||
Middleware::Ignore => unimplemented!("syncback does not work on Ignore middleware"),
|
||||
|
|
@ -111,7 +107,9 @@ pub fn extension_for_middleware(middleware: Middleware) -> &'static str {
|
|||
| Middleware::CsvDir
|
||||
| Middleware::ServerScriptDir
|
||||
| Middleware::ClientScriptDir
|
||||
| Middleware::ModuleScriptDir => {
|
||||
| Middleware::ModuleScriptDir
|
||||
| Middleware::LocalScriptDir
|
||||
| Middleware::LegacyScriptDir => {
|
||||
unimplemented!("directory middleware requires special treatment")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -325,8 +325,21 @@ pub fn get_best_middleware(snapshot: &SyncbackSnapshot) -> Middleware {
|
|||
"Folder" | "Configuration" | "Tool" | "ScreenGui" | "SurfaceGui" | "BillboardGui"
|
||||
| "AdGui" => Middleware::Dir,
|
||||
"StringValue" => Middleware::Text,
|
||||
"Script" => Middleware::ServerScript,
|
||||
"LocalScript" => Middleware::ClientScript,
|
||||
"Script" => {
|
||||
// Check RunContext to determine which middleware to use
|
||||
// RunContext enum values: Legacy = 0, Server = 1, Client = 2, Plugin = 3
|
||||
match inst.properties.get(&ustr("RunContext")) {
|
||||
Some(Variant::Enum(e)) => match e.to_u32() {
|
||||
0 => Middleware::LegacyScript,
|
||||
1 => Middleware::ServerScript,
|
||||
2 => Middleware::ClientScript,
|
||||
3 => Middleware::PluginScript,
|
||||
_ => Middleware::LegacyScript, // Unknown RunContext, default to Legacy
|
||||
},
|
||||
_ => Middleware::LegacyScript, // No RunContext property, default to Legacy
|
||||
}
|
||||
}
|
||||
"LocalScript" => Middleware::LocalScript,
|
||||
"ModuleScript" => Middleware::ModuleScript,
|
||||
"LocalizationTable" => Middleware::Csv,
|
||||
// Default: use JsonModel for everything else (becomes Dir if has children)
|
||||
|
|
@ -339,6 +352,9 @@ pub fn get_best_middleware(snapshot: &SyncbackSnapshot) -> Middleware {
|
|||
Middleware::ServerScript => Middleware::ServerScriptDir,
|
||||
Middleware::ClientScript => Middleware::ClientScriptDir,
|
||||
Middleware::ModuleScript => Middleware::ModuleScriptDir,
|
||||
Middleware::PluginScript => Middleware::ServerScriptDir, // Plugin scripts with children use server script dir for now
|
||||
Middleware::LegacyScript => Middleware::LegacyScriptDir,
|
||||
Middleware::LocalScript => Middleware::LocalScriptDir,
|
||||
Middleware::Csv => Middleware::CsvDir,
|
||||
Middleware::JsonModel | Middleware::Text => Middleware::Dir,
|
||||
_ => middleware,
|
||||
|
|
@ -431,11 +447,11 @@ impl SyncbackRules {
|
|||
Ok(globs)
|
||||
}
|
||||
|
||||
/// Returns whether Windows-invalid characters should be encoded in file
|
||||
/// names during syncback. Defaults to `false`.
|
||||
/// Returns whether special characters (including periods) should be encoded
|
||||
/// in file names during syncback. Defaults to `true`.
|
||||
#[inline]
|
||||
pub fn encode_windows_invalid_chars(&self) -> bool {
|
||||
self.encode_windows_invalid_chars.unwrap_or(false)
|
||||
self.encode_windows_invalid_chars.unwrap_or(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
660
src/web/api.rs
660
src/web/api.rs
|
|
@ -257,6 +257,54 @@ impl ApiService {
|
|||
/// Syncback an added instance by creating a file in the filesystem.
|
||||
/// The file watcher will pick up the change and update Rojo's tree.
|
||||
///
|
||||
/// Checks if a path in the Rojo tree is unique by verifying no duplicates exist
|
||||
/// at ANY level of the path (similar to ref_properties::is_path_unique).
|
||||
/// Returns true if the path is unique, false if duplicates exist at any level.
|
||||
fn is_tree_path_unique(&self, tree: &crate::snapshot::RojoTree, target_ref: Ref) -> bool {
|
||||
let mut current_ref = target_ref;
|
||||
|
||||
loop {
|
||||
let current = match tree.get_instance(current_ref) {
|
||||
Some(inst) => inst,
|
||||
None => return false,
|
||||
};
|
||||
|
||||
let parent_ref = current.parent();
|
||||
if parent_ref.is_none() {
|
||||
// Reached root - path is unique at all levels
|
||||
return true;
|
||||
}
|
||||
|
||||
let parent = match tree.get_instance(parent_ref) {
|
||||
Some(inst) => inst,
|
||||
None => return true,
|
||||
};
|
||||
|
||||
// Check if any sibling has the same name as current
|
||||
let current_name = current.name();
|
||||
let mut count = 0;
|
||||
for child_ref in parent.children() {
|
||||
if let Some(child) = tree.get_instance(*child_ref) {
|
||||
if child.name() == current_name {
|
||||
count += 1;
|
||||
if count > 1 {
|
||||
// Duplicate found at this level - path is not unique
|
||||
log::warn!(
|
||||
"Syncback: Path to '{}' is not unique - duplicate-named siblings at '{}'",
|
||||
current_name,
|
||||
parent.name()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Move up to parent and check the next level
|
||||
current_ref = parent_ref;
|
||||
}
|
||||
}
|
||||
|
||||
/// This follows the same middleware selection logic as the dedicated syncback
|
||||
/// system in `src/syncback/mod.rs` to ensure consistent behavior.
|
||||
fn syncback_added_instance(
|
||||
|
|
@ -280,6 +328,14 @@ impl ApiService {
|
|||
.get_instance(added.parent)
|
||||
.context("Parent instance not found in Rojo tree")?;
|
||||
|
||||
// Check if the parent path is unique (no duplicate-named siblings at any level)
|
||||
if !self.is_tree_path_unique(&tree, added.parent) {
|
||||
anyhow::bail!(
|
||||
"Cannot sync instance '{}' - parent path contains duplicate-named siblings",
|
||||
added.name
|
||||
);
|
||||
}
|
||||
|
||||
// Get the parent's filesystem path from its metadata
|
||||
let parent_path = parent_instance
|
||||
.metadata()
|
||||
|
|
@ -302,6 +358,54 @@ impl ApiService {
|
|||
self.syncback_instance_to_path(added, &parent_dir)
|
||||
}
|
||||
|
||||
/// Check for duplicate names among children and return the set of unique children
|
||||
/// that should be synced. Logs warnings for skipped duplicates.
|
||||
fn filter_duplicate_children<'a>(
|
||||
&self,
|
||||
children: &'a [crate::web::interface::AddedInstance],
|
||||
) -> Vec<&'a crate::web::interface::AddedInstance> {
|
||||
use std::collections::HashMap;
|
||||
|
||||
// Count occurrences of each name
|
||||
let mut name_counts: HashMap<&str, usize> = HashMap::new();
|
||||
for child in children {
|
||||
*name_counts.entry(&child.name).or_insert(0) += 1;
|
||||
}
|
||||
|
||||
// Find duplicates
|
||||
let duplicates: std::collections::HashSet<&str> = name_counts
|
||||
.iter()
|
||||
.filter(|(_, &count)| count > 1)
|
||||
.map(|(&name, _)| name)
|
||||
.collect();
|
||||
|
||||
// Log skipped duplicates
|
||||
let mut skipped_count = 0;
|
||||
for child in children {
|
||||
if duplicates.contains(child.name.as_str()) {
|
||||
log::warn!(
|
||||
"Syncback: Skipped instance '{}' ({}) - has duplicate-named siblings (cannot reliably sync)",
|
||||
child.name,
|
||||
child.class_name
|
||||
);
|
||||
skipped_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if skipped_count > 0 {
|
||||
log::warn!(
|
||||
"Syncback: Skipped {} instance(s) with duplicate-named siblings",
|
||||
skipped_count
|
||||
);
|
||||
}
|
||||
|
||||
// Return only non-duplicate children
|
||||
children
|
||||
.iter()
|
||||
.filter(|child| !duplicates.contains(child.name.as_str()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Recursively syncback an instance and its children to the filesystem.
|
||||
/// This is the internal implementation that handles the actual file creation.
|
||||
fn syncback_instance_to_path(
|
||||
|
|
@ -320,7 +424,9 @@ impl ApiService {
|
|||
)
|
||||
})?;
|
||||
|
||||
let has_children = !added.children.is_empty();
|
||||
// Filter out children with duplicate names (cannot reliably sync)
|
||||
let unique_children = self.filter_duplicate_children(&added.children);
|
||||
let has_children = !unique_children.is_empty();
|
||||
|
||||
// Determine the appropriate middleware/file format based on class name
|
||||
// This matches the logic in src/syncback/mod.rs::get_best_middleware
|
||||
|
|
@ -345,7 +451,7 @@ impl ApiService {
|
|||
"Syncback: Created ModuleScript directory at {}",
|
||||
dir_path.display()
|
||||
);
|
||||
for child in &added.children {
|
||||
for child in &unique_children {
|
||||
self.syncback_instance_to_path(child, &dir_path)?;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -378,7 +484,7 @@ impl ApiService {
|
|||
"Syncback: Created Script directory at {}",
|
||||
dir_path.display()
|
||||
);
|
||||
for child in &added.children {
|
||||
for child in &unique_children {
|
||||
self.syncback_instance_to_path(child, &dir_path)?;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -399,7 +505,7 @@ impl ApiService {
|
|||
fs::create_dir_all(&dir_path).with_context(|| {
|
||||
format!("Failed to create directory: {}", dir_path.display())
|
||||
})?;
|
||||
let init_path = dir_path.join("init.client.luau");
|
||||
let init_path = dir_path.join("init.local.luau");
|
||||
fs::write(&init_path, source.as_bytes()).with_context(|| {
|
||||
format!("Failed to write file: {}", init_path.display())
|
||||
})?;
|
||||
|
|
@ -408,11 +514,11 @@ impl ApiService {
|
|||
"Syncback: Created LocalScript directory at {}",
|
||||
dir_path.display()
|
||||
);
|
||||
for child in &added.children {
|
||||
for child in &unique_children {
|
||||
self.syncback_instance_to_path(child, &dir_path)?;
|
||||
}
|
||||
} else {
|
||||
let file_path = parent_dir.join(format!("{}.client.luau", added.name));
|
||||
let file_path = parent_dir.join(format!("{}.local.luau", added.name));
|
||||
fs::write(&file_path, source.as_bytes()).with_context(|| {
|
||||
format!("Failed to write file: {}", file_path.display())
|
||||
})?;
|
||||
|
|
@ -439,7 +545,8 @@ impl ApiService {
|
|||
};
|
||||
|
||||
// Add .gitkeep for empty directories with no metadata (matches dedicated syncback)
|
||||
if added.children.is_empty() && !has_metadata {
|
||||
// Uses !has_children which accounts for filtered duplicate children
|
||||
if !has_children && !has_metadata {
|
||||
fs::write(dir_path.join(".gitkeep"), b"")
|
||||
.with_context(|| "Failed to write .gitkeep")?;
|
||||
}
|
||||
|
|
@ -451,7 +558,7 @@ impl ApiService {
|
|||
);
|
||||
|
||||
// Recursively process children
|
||||
for child in &added.children {
|
||||
for child in &unique_children {
|
||||
self.syncback_instance_to_path(child, &dir_path)?;
|
||||
}
|
||||
}
|
||||
|
|
@ -469,7 +576,7 @@ impl ApiService {
|
|||
"Syncback: Created StringValue directory at {}",
|
||||
dir_path.display()
|
||||
);
|
||||
for child in &added.children {
|
||||
for child in &unique_children {
|
||||
self.syncback_instance_to_path(child, &dir_path)?;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -508,7 +615,7 @@ impl ApiService {
|
|||
"Syncback: Created LocalizationTable directory at {}",
|
||||
dir_path.display()
|
||||
);
|
||||
for child in &added.children {
|
||||
for child in &unique_children {
|
||||
self.syncback_instance_to_path(child, &dir_path)?;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -542,7 +649,7 @@ impl ApiService {
|
|||
);
|
||||
|
||||
// Recursively process children
|
||||
for child in &added.children {
|
||||
for child in &unique_children {
|
||||
self.syncback_instance_to_path(child, &dir_path)?;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -752,11 +859,9 @@ impl ApiService {
|
|||
/// For `Script` class:
|
||||
/// - RunContext: Client → "client"
|
||||
/// - RunContext: Server → "server"
|
||||
/// - RunContext: Legacy → "server" (default for legacy mode)
|
||||
/// - RunContext: Legacy → "legacy"
|
||||
/// - RunContext: Plugin → "plugin"
|
||||
/// - No RunContext → "server" (default)
|
||||
///
|
||||
/// This ensures proper round-tripping regardless of emitLegacyScripts mode.
|
||||
/// - No RunContext → "legacy" (default)
|
||||
fn get_script_suffix_for_run_context(
|
||||
&self,
|
||||
added: &crate::web::interface::AddedInstance,
|
||||
|
|
@ -779,16 +884,16 @@ impl ApiService {
|
|||
return match name.as_ref() {
|
||||
"Client" => "client",
|
||||
"Server" => "server",
|
||||
"Legacy" => "server",
|
||||
"Legacy" => "legacy",
|
||||
"Plugin" => "plugin",
|
||||
_ => "server",
|
||||
_ => "legacy",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Default to server if no RunContext or unrecognized
|
||||
"server"
|
||||
// Default to legacy if no RunContext or unrecognized
|
||||
"legacy"
|
||||
}
|
||||
|
||||
/// Write an adjacent meta file for scripts without children.
|
||||
|
|
@ -1596,15 +1701,13 @@ mod tests {
|
|||
// Test that script class names result in correct file extensions
|
||||
let test_cases = vec![
|
||||
("ModuleScript", "TestModule", "TestModule.luau"),
|
||||
("Script", "TestScript", "TestScript.server.luau"),
|
||||
("LocalScript", "TestClient", "TestClient.client.luau"),
|
||||
("LocalScript", "TestClient", "TestClient.local.luau"),
|
||||
];
|
||||
|
||||
for (class_name, name, expected) in test_cases {
|
||||
let file_name = match class_name {
|
||||
"ModuleScript" => format!("{}.luau", name),
|
||||
"Script" => format!("{}.server.luau", name),
|
||||
"LocalScript" => format!("{}.client.luau", name),
|
||||
"LocalScript" => format!("{}.local.luau", name),
|
||||
_ => format!("{}.model.json", name),
|
||||
};
|
||||
assert_eq!(
|
||||
|
|
@ -1758,8 +1861,8 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_run_context_legacy_gives_server_suffix() {
|
||||
// Script with RunContext: Legacy should produce .server.luau (for legacy mode)
|
||||
fn test_run_context_legacy_gives_legacy_suffix() {
|
||||
// Script with RunContext: Legacy should produce .legacy.luau
|
||||
let run_context_enums = rbx_reflection_database::get()
|
||||
.ok()
|
||||
.and_then(|db| db.enums.get("RunContext"))
|
||||
|
|
@ -1792,14 +1895,13 @@ mod tests {
|
|||
// For Script class, the file suffix is determined by RunContext:
|
||||
// - Client → .client.luau
|
||||
// - Server → .server.luau
|
||||
// - Legacy → .server.luau
|
||||
// - Legacy → .legacy.luau
|
||||
// - Plugin → .plugin.luau
|
||||
// This allows proper round-tripping regardless of emitLegacyScripts mode
|
||||
|
||||
let expected_mappings = vec![
|
||||
("Client", "client"),
|
||||
("Server", "server"),
|
||||
("Legacy", "server"),
|
||||
("Legacy", "legacy"),
|
||||
("Plugin", "plugin"),
|
||||
];
|
||||
|
||||
|
|
@ -1807,9 +1909,9 @@ mod tests {
|
|||
let suffix = match run_context {
|
||||
"Client" => "client",
|
||||
"Server" => "server",
|
||||
"Legacy" => "server",
|
||||
"Legacy" => "legacy",
|
||||
"Plugin" => "plugin",
|
||||
_ => "server",
|
||||
_ => "legacy",
|
||||
};
|
||||
assert_eq!(
|
||||
suffix, expected_suffix,
|
||||
|
|
@ -1820,14 +1922,14 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_local_script_always_client() {
|
||||
// LocalScript class always produces .client.luau regardless of any properties
|
||||
fn test_local_script_always_local() {
|
||||
// LocalScript class always produces .local.luau regardless of any properties
|
||||
let class_name = "LocalScript";
|
||||
let expected_suffix = "client";
|
||||
let expected_suffix = "local";
|
||||
|
||||
// LocalScript doesn't check RunContext - it's always client
|
||||
// LocalScript doesn't check RunContext - it's always local
|
||||
let suffix = if class_name == "LocalScript" {
|
||||
"client"
|
||||
"local"
|
||||
} else {
|
||||
"unknown"
|
||||
};
|
||||
|
|
@ -2136,8 +2238,6 @@ mod tests {
|
|||
// =========================================================================
|
||||
mod run_context_comprehensive_tests {
|
||||
use super::*;
|
||||
use rbx_dom_weak::types::Enum;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Helper to get RunContext enum value by name
|
||||
fn get_run_context_value(name: &str) -> Option<u32> {
|
||||
|
|
@ -2817,7 +2917,7 @@ mod tests {
|
|||
// In scripts-only mode, all instances get ignoreUnknownInstances: true
|
||||
// This prevents accidental deletion of non-script instances
|
||||
let folder = "Folder";
|
||||
let is_script = is_script_class(folder);
|
||||
let _is_script = is_script_class(folder);
|
||||
|
||||
// Non-scripts should have ignoreUnknownInstances set
|
||||
let should_set_ignore = true; // All instances in scripts-only mode
|
||||
|
|
@ -2868,18 +2968,18 @@ mod tests {
|
|||
expected_extension: ".luau",
|
||||
description: "ModuleScript without RunContext",
|
||||
},
|
||||
// LocalScript - always .client.luau
|
||||
// LocalScript - always .local.luau
|
||||
TestCase {
|
||||
class_name: "LocalScript",
|
||||
run_context: None,
|
||||
expected_extension: ".client.luau",
|
||||
expected_extension: ".local.luau",
|
||||
description: "LocalScript",
|
||||
},
|
||||
// Script with various RunContext values
|
||||
TestCase {
|
||||
class_name: "Script",
|
||||
run_context: None,
|
||||
expected_extension: ".server.luau",
|
||||
expected_extension: ".legacy.luau",
|
||||
description: "Script without RunContext (default)",
|
||||
},
|
||||
TestCase {
|
||||
|
|
@ -2897,7 +2997,7 @@ mod tests {
|
|||
TestCase {
|
||||
class_name: "Script",
|
||||
run_context: Some("Legacy"),
|
||||
expected_extension: ".server.luau",
|
||||
expected_extension: ".legacy.luau",
|
||||
description: "Script with RunContext::Legacy",
|
||||
},
|
||||
TestCase {
|
||||
|
|
@ -2911,16 +3011,16 @@ mod tests {
|
|||
for case in test_cases {
|
||||
let suffix = match case.class_name {
|
||||
"ModuleScript" => String::new(),
|
||||
"LocalScript" => "client".to_string(),
|
||||
"LocalScript" => "local".to_string(),
|
||||
"Script" => {
|
||||
// Match on RunContext name to determine suffix
|
||||
match case.run_context {
|
||||
Some("Client") => "client",
|
||||
Some("Server") => "server",
|
||||
Some("Legacy") => "server",
|
||||
Some("Legacy") => "legacy",
|
||||
Some("Plugin") => "plugin",
|
||||
None => "server",
|
||||
_ => "server",
|
||||
None => "legacy",
|
||||
_ => "legacy",
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
|
|
@ -3003,4 +3103,472 @@ mod tests {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Duplicate Path Detection Tests
|
||||
// =========================================================================
|
||||
mod duplicate_path_tests {
|
||||
// Helper to simulate sibling name checking
|
||||
fn has_duplicate_sibling_names(names: &[&str], target_name: &str) -> bool {
|
||||
let count = names.iter().filter(|&&n| n == target_name).count();
|
||||
count > 1
|
||||
}
|
||||
|
||||
// Simulates the duplicate children filter logic
|
||||
fn filter_duplicate_names<'a>(names: &[&'a str]) -> Vec<&'a str> {
|
||||
let mut counts: std::collections::HashMap<&str, usize> =
|
||||
std::collections::HashMap::new();
|
||||
for name in names {
|
||||
*counts.entry(name).or_insert(0) += 1;
|
||||
}
|
||||
|
||||
names
|
||||
.iter()
|
||||
.filter(|&&name| counts.get(name).copied().unwrap_or(0) <= 1)
|
||||
.copied()
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_duplicates_all_pass() {
|
||||
let names = vec!["Script1", "Script2", "Script3", "Folder"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(filtered.len(), 4, "All unique names should pass");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duplicate_siblings_filtered() {
|
||||
let names = vec!["Script", "Script", "Other"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(
|
||||
filtered.len(),
|
||||
1,
|
||||
"Duplicate 'Script' entries should be filtered"
|
||||
);
|
||||
assert_eq!(filtered[0], "Other", "Only 'Other' should remain");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_duplicates_filtered() {
|
||||
let names = vec!["A", "A", "B", "B", "C"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(filtered.len(), 1, "Only unique 'C' should remain");
|
||||
assert_eq!(filtered[0], "C");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_all_duplicates_empty_result() {
|
||||
let names = vec!["Same", "Same", "Same"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(
|
||||
filtered.len(),
|
||||
0,
|
||||
"All duplicates should result in empty list"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sibling_detection_positive() {
|
||||
let siblings = vec!["Script", "Script", "Other"];
|
||||
assert!(
|
||||
has_duplicate_sibling_names(&siblings, "Script"),
|
||||
"'Script' should be detected as having duplicate siblings"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sibling_detection_negative() {
|
||||
let siblings = vec!["Script", "Folder", "Model"];
|
||||
assert!(
|
||||
!has_duplicate_sibling_names(&siblings, "Script"),
|
||||
"'Script' should NOT be detected as duplicate with unique siblings"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sibling_detection_not_in_list() {
|
||||
let siblings = vec!["A", "B", "C"];
|
||||
assert!(
|
||||
!has_duplicate_sibling_names(&siblings, "D"),
|
||||
"'D' not in list should not have duplicates"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_path_uniqueness_concept() {
|
||||
// Test the concept: path is unique only if NO level has duplicates
|
||||
//
|
||||
// Tree:
|
||||
// Root
|
||||
// ├─ FolderA
|
||||
// │ └─ Script
|
||||
// └─ FolderA (duplicate!)
|
||||
// └─ Script
|
||||
//
|
||||
// Path "Root/FolderA/Script" is NOT unique because FolderA is duplicated
|
||||
|
||||
let root_children = vec!["FolderA", "FolderA"];
|
||||
let folder_children = vec!["Script"];
|
||||
|
||||
// Check at root level - duplicates exist
|
||||
let has_dup_at_root = has_duplicate_sibling_names(&root_children, "FolderA");
|
||||
assert!(
|
||||
has_dup_at_root,
|
||||
"FolderA should be detected as duplicate at root level"
|
||||
);
|
||||
|
||||
// Check at folder level - no duplicates
|
||||
let has_dup_at_folder = has_duplicate_sibling_names(&folder_children, "Script");
|
||||
assert!(
|
||||
!has_dup_at_folder,
|
||||
"Script has no duplicate siblings within its parent"
|
||||
);
|
||||
|
||||
// But the PATH is still not unique because of the ancestor duplicate
|
||||
let path_is_unique = !has_dup_at_root;
|
||||
assert!(
|
||||
!path_is_unique,
|
||||
"Path should NOT be unique due to ancestor duplicate"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_path_uniqueness_deep_hierarchy() {
|
||||
// Tree:
|
||||
// Root (unique)
|
||||
// └─ Level1 (unique)
|
||||
// └─ Level2 (has duplicate sibling)
|
||||
// └─ Target
|
||||
//
|
||||
// Path to Target is NOT unique
|
||||
|
||||
let level1_children = vec!["Level2", "Level2", "Other"];
|
||||
let level2_children = vec!["Target"];
|
||||
|
||||
let has_dup_at_level1 = has_duplicate_sibling_names(&level1_children, "Level2");
|
||||
assert!(has_dup_at_level1, "Level2 has duplicate at Level1");
|
||||
|
||||
// Even though Target itself has no duplicates, path is not unique
|
||||
let has_dup_at_level2 = has_duplicate_sibling_names(&level2_children, "Target");
|
||||
assert!(!has_dup_at_level2, "Target has no duplicate at Level2");
|
||||
|
||||
// Path uniqueness requires ALL levels to be unique
|
||||
let path_unique = !has_dup_at_level1 && !has_dup_at_level2;
|
||||
assert!(
|
||||
!path_unique,
|
||||
"Path should NOT be unique due to Level2 duplicate"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_path_uniqueness_fully_unique() {
|
||||
// Tree:
|
||||
// Root
|
||||
// └─ Folder (unique)
|
||||
// └─ SubFolder (unique)
|
||||
// └─ Script (unique)
|
||||
|
||||
let root_children = vec!["Folder"];
|
||||
let folder_children = vec!["SubFolder"];
|
||||
let sub_children = vec!["Script"];
|
||||
|
||||
let root_unique = !has_duplicate_sibling_names(&root_children, "Folder");
|
||||
let folder_unique = !has_duplicate_sibling_names(&folder_children, "SubFolder");
|
||||
let sub_unique = !has_duplicate_sibling_names(&sub_children, "Script");
|
||||
|
||||
let path_unique = root_unique && folder_unique && sub_unique;
|
||||
assert!(
|
||||
path_unique,
|
||||
"Path should be unique when all levels are unique"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_case_sensitive_duplicates() {
|
||||
// Roblox names are case-sensitive, so "Script" and "script" are different
|
||||
let names = vec!["Script", "script", "SCRIPT"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(
|
||||
filtered.len(),
|
||||
3,
|
||||
"Case-different names should all be kept (case-sensitive)"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_names_handled() {
|
||||
let names = vec!["", "", "Valid"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(
|
||||
filtered.len(),
|
||||
1,
|
||||
"Empty string duplicates should be filtered"
|
||||
);
|
||||
assert_eq!(filtered[0], "Valid");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_special_characters_in_names() {
|
||||
// Names with special characters that might cause filesystem issues
|
||||
// are handled separately by validate_file_name, but duplicates should still work
|
||||
let names = vec!["Script (1)", "Script (2)", "Script (1)"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(
|
||||
filtered.len(),
|
||||
1,
|
||||
"Only 'Script (2)' should remain after filtering duplicates"
|
||||
);
|
||||
assert_eq!(filtered[0], "Script (2)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_whitespace_names() {
|
||||
// Names with leading/trailing whitespace are technically different
|
||||
let names = vec!["Script", " Script", "Script "];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(
|
||||
filtered.len(),
|
||||
3,
|
||||
"Whitespace-different names should all be kept"
|
||||
);
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Non-Script Duplicate Tests - Duplicates apply to ALL instance types
|
||||
// =====================================================================
|
||||
|
||||
#[test]
|
||||
fn test_duplicate_folders_filtered() {
|
||||
// Duplicate Folders should be filtered just like scripts
|
||||
let names = vec!["MyFolder", "MyFolder", "OtherFolder"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(filtered.len(), 1, "Duplicate 'MyFolder' should be filtered");
|
||||
assert_eq!(filtered[0], "OtherFolder");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duplicate_parts_filtered() {
|
||||
// Duplicate Parts should be filtered
|
||||
let names = vec!["Part", "Part", "Baseplate"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(filtered.len(), 1, "Duplicate 'Part' should be filtered");
|
||||
assert_eq!(filtered[0], "Baseplate");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duplicate_models_filtered() {
|
||||
// Duplicate Models should be filtered
|
||||
let names = vec!["Car", "Car", "House"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(
|
||||
filtered.len(),
|
||||
1,
|
||||
"Duplicate 'Car' models should be filtered"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duplicate_values_filtered() {
|
||||
// Duplicate IntValues/StringValues should be filtered
|
||||
let names = vec!["Score", "Score", "Health"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(
|
||||
filtered.len(),
|
||||
1,
|
||||
"Duplicate 'Score' values should be filtered"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duplicate_gui_elements_filtered() {
|
||||
// Duplicate GUI elements should be filtered
|
||||
let names = vec!["MainFrame", "MainFrame", "Sidebar"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(
|
||||
filtered.len(),
|
||||
1,
|
||||
"Duplicate 'MainFrame' GUI should be filtered"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mixed_types_same_name_filtered() {
|
||||
// Even if types differ, same names are duplicates (filesystem perspective)
|
||||
// E.g., a Folder named "Data" and a Script named "Data" would conflict
|
||||
let names = vec!["Data", "Data"]; // Could be Folder + Script
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(
|
||||
filtered.len(),
|
||||
0,
|
||||
"Same-named instances of different types still conflict"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_folder_hierarchy_duplicates() {
|
||||
// Duplicates in folder hierarchies
|
||||
// Root/
|
||||
// ├─ Enemies/
|
||||
// │ └─ Enemy (unique)
|
||||
// └─ Enemies/ (duplicate!)
|
||||
// └─ Enemy
|
||||
|
||||
let root_children = vec!["Enemies", "Enemies", "Players"];
|
||||
let enemies_unique = !has_duplicate_sibling_names(&root_children, "Enemies");
|
||||
assert!(
|
||||
!enemies_unique,
|
||||
"Duplicate 'Enemies' folders should be detected"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_part_ancestor_duplicates() {
|
||||
// A Part deep in hierarchy with duplicate ancestor
|
||||
// Workspace/
|
||||
// ├─ Zone/
|
||||
// │ └─ SpawnPoint (Part)
|
||||
// └─ Zone/ (duplicate!)
|
||||
// └─ SpawnPoint (Part)
|
||||
|
||||
let workspace_children = vec!["Zone", "Zone"];
|
||||
let zone_unique = !has_duplicate_sibling_names(&workspace_children, "Zone");
|
||||
assert!(
|
||||
!zone_unique,
|
||||
"Duplicate 'Zone' ancestors make Part paths ambiguous"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_remote_event_duplicates() {
|
||||
// RemoteEvents with duplicate names
|
||||
let names = vec!["FireBullet", "FireBullet", "TakeDamage"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(
|
||||
filtered.len(),
|
||||
1,
|
||||
"Duplicate RemoteEvents should be filtered"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_configuration_duplicates() {
|
||||
// Configuration instances with duplicates
|
||||
let names = vec!["Settings", "Settings", "Config"];
|
||||
let filtered = filter_duplicate_names(&names);
|
||||
assert_eq!(
|
||||
filtered.len(),
|
||||
1,
|
||||
"Duplicate Configurations should be filtered"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Duplicate Path Detection - Integration Scenarios
|
||||
// =========================================================================
|
||||
mod duplicate_path_integration_tests {
|
||||
|
||||
#[test]
|
||||
fn test_syncback_skips_duplicate_children() {
|
||||
// When syncing back children, duplicates should be skipped
|
||||
// This test verifies the filter_duplicate_children logic
|
||||
|
||||
let children_names = vec!["ChildA", "ChildB", "ChildA", "ChildC"];
|
||||
let unique: Vec<_> = children_names
|
||||
.iter()
|
||||
.filter(|&&name| children_names.iter().filter(|&&n| n == name).count() == 1)
|
||||
.collect();
|
||||
|
||||
assert_eq!(unique.len(), 2, "ChildB and ChildC should be kept");
|
||||
assert!(unique.contains(&&"ChildB"));
|
||||
assert!(unique.contains(&&"ChildC"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_recursive_duplicate_handling() {
|
||||
// Test that duplicates at any level are handled
|
||||
//
|
||||
// Parent/
|
||||
// ├─ Child1/
|
||||
// │ ├─ GrandChild (duplicate)
|
||||
// │ └─ GrandChild (duplicate)
|
||||
// └─ Child2/
|
||||
// └─ GrandChild (unique within its parent)
|
||||
|
||||
let child1_grandchildren = vec!["GrandChild", "GrandChild"];
|
||||
let child2_grandchildren = vec!["GrandChild"];
|
||||
|
||||
// Child1's grandchildren have duplicates
|
||||
let child1_filtered: Vec<_> = child1_grandchildren
|
||||
.iter()
|
||||
.filter(|&&name| child1_grandchildren.iter().filter(|&&n| n == name).count() == 1)
|
||||
.collect();
|
||||
assert_eq!(
|
||||
child1_filtered.len(),
|
||||
0,
|
||||
"Child1's duplicate grandchildren filtered"
|
||||
);
|
||||
|
||||
// Child2's grandchild is unique
|
||||
let child2_filtered: Vec<_> = child2_grandchildren
|
||||
.iter()
|
||||
.filter(|&&name| child2_grandchildren.iter().filter(|&&n| n == name).count() == 1)
|
||||
.collect();
|
||||
assert_eq!(child2_filtered.len(), 1, "Child2's unique grandchild kept");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duplicate_log_message_format() {
|
||||
// Verify the expected log message format for skipped duplicates
|
||||
let class_name = "ModuleScript";
|
||||
let full_name = "game.ReplicatedStorage.DuplicateScript";
|
||||
|
||||
let expected_msg = format!(
|
||||
"Skipped instance '{}' ({}) - path contains duplicate-named siblings (cannot reliably sync)",
|
||||
full_name, class_name
|
||||
);
|
||||
|
||||
assert!(expected_msg.contains(full_name));
|
||||
assert!(expected_msg.contains(class_name));
|
||||
assert!(expected_msg.contains("duplicate-named siblings"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parent_path_validation() {
|
||||
// When pulling an instance, we must verify the parent path is unique
|
||||
// This simulates the is_tree_path_unique check
|
||||
|
||||
// Scenario: Trying to add a script under a folder that has duplicate siblings
|
||||
let parent_path_levels = vec![
|
||||
("Root", vec!["FolderA", "FolderA"]), // Duplicate at this level!
|
||||
];
|
||||
|
||||
let path_unique = parent_path_levels
|
||||
.iter()
|
||||
.all(|(target, siblings)| siblings.iter().filter(|&&s| s == *target).count() == 1);
|
||||
|
||||
assert!(
|
||||
!path_unique,
|
||||
"Parent path with duplicates should fail validation"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_valid_parent_path() {
|
||||
// Valid parent path with no duplicates at any level
|
||||
let parent_path_levels = vec![
|
||||
(
|
||||
"ReplicatedStorage",
|
||||
vec!["Workspace", "ReplicatedStorage", "ServerStorage"],
|
||||
),
|
||||
("Shared", vec!["Shared", "Client", "Server"]),
|
||||
];
|
||||
|
||||
let path_unique = parent_path_levels
|
||||
.iter()
|
||||
.all(|(target, siblings)| siblings.iter().filter(|&&s| s == *target).count() == 1);
|
||||
|
||||
assert!(path_unique, "Valid parent path should pass validation");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue