From e1f8a24cfd6c3b75136060bdfafd471c9299adf9 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Thu, 3 Aug 2023 15:38:43 +1000 Subject: [PATCH 01/22] Initial Implimentation --- src/project.rs | 6 +++- src/snapshot_middleware/lua.rs | 56 +++++++++++++++++++++++++++------- src/snapshot_middleware/mod.rs | 1 + 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/project.rs b/src/project.rs index e70005d06..474344662 100644 --- a/src/project.rs +++ b/src/project.rs @@ -8,7 +8,7 @@ use std::{ use serde::{Deserialize, Serialize}; use thiserror::Error; -use crate::{glob::Glob, resolution::UnresolvedValue}; +use crate::{glob::Glob, resolution::UnresolvedValue, snapshot_middleware::ScriptContextType}; static PROJECT_FILENAME: &str = "default.project.json"; @@ -73,6 +73,10 @@ pub struct Project { #[serde(skip_serializing_if = "Option::is_none")] pub serve_address: Option, + /// The mode to use when mapping scripts onto Roblox + #[serde(default)] + pub script_type: ScriptContextType, + /// 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")] diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index ba2216263..19c2e9e05 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -1,8 +1,10 @@ use std::{path::Path, str}; -use anyhow::Context; +use anyhow::{Context, format_err}; use maplit::hashmap; use memofs::{IoResultExt, Vfs}; +use rbx_dom_weak::types::Enum; +use serde::{Deserialize, Serialize}; use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot}; @@ -12,6 +14,20 @@ use super::{ util::match_trailing, }; +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)] +pub enum ScriptContextType { + #[default] + Class, + RunContext +} + +#[derive(Debug)] +enum ScriptType { + Server, + Client, + Module, +} + /// Core routine for turning Lua files into snapshots. pub fn snapshot_lua( context: &InstanceContext, @@ -20,36 +36,54 @@ pub fn snapshot_lua( ) -> anyhow::Result> { let file_name = path.file_name().unwrap().to_string_lossy(); - let (class_name, instance_name) = if let Some(name) = match_trailing(&file_name, ".server.lua") + let is_runcontext_enabled = true; //project.script_type == ScriptType::RunContext; + + let run_context = &rbx_reflection_database::get().enums.get("RunContext").ok_or_else(|| format_err!("Unable to get RunContext enums!"))?.items; + + let (script_type, instance_name) = if let Some(name) = match_trailing(&file_name, ".server.lua") { - ("Script", name) + (ScriptType::Server, name) } else if let Some(name) = match_trailing(&file_name, ".client.lua") { - ("LocalScript", name) + (ScriptType::Client, name) } else if let Some(name) = match_trailing(&file_name, ".lua") { - ("ModuleScript", name) + (ScriptType::Module, name) } else if let Some(name) = match_trailing(&file_name, ".server.luau") { - ("Script", name) + (ScriptType::Server, name) } else if let Some(name) = match_trailing(&file_name, ".client.luau") { - ("LocalScript", name) + (ScriptType::Client, name) } else if let Some(name) = match_trailing(&file_name, ".luau") { - ("ModuleScript", name) + (ScriptType::Module, name) } else { return Ok(None); }; + let (class_name, run_context) = match (is_runcontext_enabled, script_type) { + (true, ScriptType::Server) => ("Script", run_context.get("Server")), + (true, ScriptType::Client) => ("Script", run_context.get("Client")), + (false, ScriptType::Server) => ("Script", run_context.get("Legacy")), + (false, ScriptType::Client) => ("LocalScript", None), + (_, ScriptType::Module) => ("ModuleScript", None), + }; + let contents = vfs.read(path)?; let contents_str = str::from_utf8(&contents) .with_context(|| format!("File was not valid UTF-8: {}", path.display()))? .to_owned(); + let mut properties = hashmap! { + "Source".to_owned() => contents_str.into(), + }; + + if let Some(run_context) = run_context { + properties.insert("RunContext".to_owned(), Enum::from_u32(run_context.to_owned()).into()); + } + let meta_path = path.with_file_name(format!("{}.meta.json", instance_name)); let mut snapshot = InstanceSnapshot::new() .name(instance_name) .class_name(class_name) - .properties(hashmap! { - "Source".to_owned() => contents_str.into(), - }) + .properties(properties) .metadata( InstanceMetadata::new() .instigating_source(path) diff --git a/src/snapshot_middleware/mod.rs b/src/snapshot_middleware/mod.rs index c690a2239..902402e58 100644 --- a/src/snapshot_middleware/mod.rs +++ b/src/snapshot_middleware/mod.rs @@ -39,6 +39,7 @@ use self::{ }; pub use self::project::snapshot_project_node; +pub use self::lua::ScriptContextType; /// The main entrypoint to the snapshot function. This function can be pointed /// at any path and will return something if Rojo knows how to deal with it. From ddc4425b4e576864083f4cf201843d57d9bda2d3 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Thu, 3 Aug 2023 18:03:27 +1000 Subject: [PATCH 02/22] chore: review comments --- plugin/modules/flipper | 1 + plugin/modules/promise | 1 + plugin/modules/roact | 1 + plugin/modules/t | 1 + plugin/modules/testez | 1 + src/snapshot_middleware/lua.rs | 8 ++++---- src/snapshot_middleware/mod.rs | 3 +-- 7 files changed, 10 insertions(+), 6 deletions(-) create mode 160000 plugin/modules/flipper create mode 160000 plugin/modules/promise create mode 160000 plugin/modules/roact create mode 160000 plugin/modules/t create mode 160000 plugin/modules/testez diff --git a/plugin/modules/flipper b/plugin/modules/flipper new file mode 160000 index 000000000..4cf7a03cb --- /dev/null +++ b/plugin/modules/flipper @@ -0,0 +1 @@ +Subproject commit 4cf7a03cb6776ec0af41b6a50988aa70e5c9cc3c diff --git a/plugin/modules/promise b/plugin/modules/promise new file mode 160000 index 000000000..7fb09d103 --- /dev/null +++ b/plugin/modules/promise @@ -0,0 +1 @@ +Subproject commit 7fb09d103f4a680cbd61d5348ec9c5d50244a8e0 diff --git a/plugin/modules/roact b/plugin/modules/roact new file mode 160000 index 000000000..f7d2f1ce1 --- /dev/null +++ b/plugin/modules/roact @@ -0,0 +1 @@ +Subproject commit f7d2f1ce1dd69120f457c2f8032bb184eb8f0c29 diff --git a/plugin/modules/t b/plugin/modules/t new file mode 160000 index 000000000..f643b5068 --- /dev/null +++ b/plugin/modules/t @@ -0,0 +1 @@ +Subproject commit f643b50682c24ec8d6ac3e11f41ee8cbbb2bcecb diff --git a/plugin/modules/testez b/plugin/modules/testez new file mode 160000 index 000000000..25d957d4d --- /dev/null +++ b/plugin/modules/testez @@ -0,0 +1 @@ +Subproject commit 25d957d4d5c4c02a52843ef43e72f21f973c2908 diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 19c2e9e05..62fec6295 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -18,7 +18,7 @@ use super::{ pub enum ScriptContextType { #[default] Class, - RunContext + RunContext, } #[derive(Debug)] @@ -36,9 +36,9 @@ pub fn snapshot_lua( ) -> anyhow::Result> { let file_name = path.file_name().unwrap().to_string_lossy(); - let is_runcontext_enabled = true; //project.script_type == ScriptType::RunContext; + let is_run_context_enabled = true; //project.script_type == ScriptType::RunContext; - let run_context = &rbx_reflection_database::get().enums.get("RunContext").ok_or_else(|| format_err!("Unable to get RunContext enums!"))?.items; + let run_context = &rbx_reflection_database::get().enums.get("RunContext").expect("Unable to get RunContext enums!").items; let (script_type, instance_name) = if let Some(name) = match_trailing(&file_name, ".server.lua") { @@ -57,7 +57,7 @@ pub fn snapshot_lua( return Ok(None); }; - let (class_name, run_context) = match (is_runcontext_enabled, script_type) { + let (class_name, run_context) = match (is_run_context_enabled, script_type) { (true, ScriptType::Server) => ("Script", run_context.get("Server")), (true, ScriptType::Client) => ("Script", run_context.get("Client")), (false, ScriptType::Server) => ("Script", run_context.get("Legacy")), diff --git a/src/snapshot_middleware/mod.rs b/src/snapshot_middleware/mod.rs index 902402e58..87b1ccfc8 100644 --- a/src/snapshot_middleware/mod.rs +++ b/src/snapshot_middleware/mod.rs @@ -38,8 +38,7 @@ use self::{ util::PathExt, }; -pub use self::project::snapshot_project_node; -pub use self::lua::ScriptContextType; +pub use self::{project::snapshot_project_node, lua::ScriptContextType}; /// The main entrypoint to the snapshot function. This function can be pointed /// at any path and will return something if Rojo knows how to deal with it. From cf04ad399d97a04eb683a5b874c088f32aa60670 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Fri, 4 Aug 2023 18:48:49 +1000 Subject: [PATCH 03/22] Update src/snapshot_middleware/lua.rs Co-authored-by: Micah --- src/snapshot_middleware/lua.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 62fec6295..68a4fd222 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -1,6 +1,6 @@ use std::{path::Path, str}; -use anyhow::{Context, format_err}; +use anyhow::{Context}; use maplit::hashmap; use memofs::{IoResultExt, Vfs}; use rbx_dom_weak::types::Enum; From bc66c5abc24420e6ca4211523cdf36379e2a058b Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Fri, 4 Aug 2023 18:54:27 +1000 Subject: [PATCH 04/22] Fix Documentation of script_type [skip ci] Co-authored-by: Micah --- src/project.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/project.rs b/src/project.rs index 474344662..a2831c760 100644 --- a/src/project.rs +++ b/src/project.rs @@ -73,7 +73,9 @@ pub struct Project { #[serde(skip_serializing_if = "Option::is_none")] pub serve_address: Option, - /// The mode to use when mapping scripts onto Roblox + /// The mode to use when mapping scripts into Roblox. + /// Can be either `Class` or `RunContext` and determines whether script + /// behavior is set using the `RunContext` property or the script's `ClassName`. #[serde(default)] pub script_type: ScriptContextType, From bfc7a0dfa018a8c56088f8c1e91f772cbd85ad26 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Fri, 4 Aug 2023 19:56:31 +1000 Subject: [PATCH 05/22] Pass through RunContext project setting --- src/serve_session.rs | 2 +- src/snapshot/metadata.rs | 43 ++++++++++---- ..._snapshot__tests__apply__add_property.snap | 3 +- ...s__apply__remove_property_after_patch.snap | 3 +- ...tests__apply__remove_property_initial.snap | 3 +- ...tests__apply__set_name_and_class_name.snap | 3 +- ...__snapshot__tests__compute__add_child.snap | 3 +- src/snapshot_middleware/csv.rs | 2 +- src/snapshot_middleware/dir.rs | 2 +- src/snapshot_middleware/json.rs | 2 +- src/snapshot_middleware/lua.rs | 56 +++++++++++-------- src/snapshot_middleware/project.rs | 2 +- src/snapshot_middleware/rbxm.rs | 2 +- src/snapshot_middleware/rbxmx.rs | 2 +- ...t_middleware__csv__test__csv_from_vfs.snap | 3 +- ..._middleware__csv__test__csv_with_meta.snap | 3 +- ...t_middleware__dir__test__empty_folder.snap | 3 +- ...ddleware__dir__test__folder_in_folder.snap | 6 +- ...leware__json__test__instance_from_vfs.snap | 3 +- ...are__json_model__test__model_from_vfs.snap | 6 +- ...on_model__test__model_from_vfs_legacy.snap | 6 +- ...iddleware__lua__test__client_from_vfs.snap | 3 +- ...ware__lua__test__init_module_from_vfs.snap | 3 +- ...iddleware__lua__test__module_from_vfs.snap | 3 +- ...ddleware__lua__test__module_with_meta.snap | 3 +- ...iddleware__lua__test__script_disabled.snap | 5 +- ...ddleware__lua__test__script_with_meta.snap | 5 +- ...iddleware__lua__test__server_from_vfs.snap | 5 +- ...oject__test__project_from_direct_file.snap | 3 +- ...e__project__test__project_from_folder.snap | 3 +- ...test__project_path_property_overrides.snap | 3 +- ..._project__test__project_with_children.snap | 6 +- ...t__test__project_with_path_to_project.snap | 3 +- ...ct_with_path_to_project_with_children.snap | 6 +- ...oject__test__project_with_path_to_txt.snap | 3 +- ...est__project_with_resolved_properties.snap | 3 +- ...t__project_with_unresolved_properties.snap | 3 +- ...leware__toml__test__instance_from_vfs.snap | 3 +- ...dleware__txt__test__instance_from_vfs.snap | 3 +- src/snapshot_middleware/toml.rs | 2 +- src/snapshot_middleware/txt.rs | 2 +- 41 files changed, 149 insertions(+), 79 deletions(-) diff --git a/src/serve_session.rs b/src/serve_session.rs index 9dab5446e..4f0b7b6df 100644 --- a/src/serve_session.rs +++ b/src/serve_session.rs @@ -123,7 +123,7 @@ impl ServeSession { let root_id = tree.get_root_id(); - let instance_context = InstanceContext::default(); + let instance_context = InstanceContext::from(root_project.script_type); log::trace!("Generating snapshot of instances from VFS"); let snapshot = snapshot_from_vfs(&instance_context, &vfs, start_path)?; diff --git a/src/snapshot/metadata.rs b/src/snapshot/metadata.rs index 192a00013..b18b06df1 100644 --- a/src/snapshot/metadata.rs +++ b/src/snapshot/metadata.rs @@ -6,7 +6,7 @@ use std::{ use serde::{Deserialize, Serialize}; -use crate::{glob::Glob, path_serializer, project::ProjectNode}; +use crate::{glob::Glob, path_serializer, project::ProjectNode, snapshot_middleware::ScriptContextType}; /// Rojo-specific metadata that can be associated with an instance or a snapshot /// of an instance. @@ -55,15 +55,6 @@ pub struct InstanceMetadata { } impl InstanceMetadata { - pub fn new() -> Self { - Self { - ignore_unknown_instances: false, - instigating_source: None, - relevant_paths: Vec::new(), - context: InstanceContext::default(), - } - } - pub fn ignore_unknown_instances(self, ignore_unknown_instances: bool) -> Self { Self { ignore_unknown_instances, @@ -93,9 +84,25 @@ impl InstanceMetadata { } } +impl From<&InstanceContext> for InstanceMetadata { + fn from(context: &InstanceContext) -> Self { + Self { + ignore_unknown_instances: false, + instigating_source: None, + relevant_paths: Vec::new(), + context: context.to_owned(), + } + } +} + impl Default for InstanceMetadata { fn default() -> Self { - Self::new() + Self { + ignore_unknown_instances: false, + instigating_source: None, + relevant_paths: Vec::new(), + context: InstanceContext::from(ScriptContextType::Class), + } } } @@ -103,6 +110,7 @@ impl Default for InstanceMetadata { pub struct InstanceContext { #[serde(skip_serializing_if = "Vec::is_empty")] pub path_ignore_rules: Arc>, + pub script_type: ScriptContextType, } impl InstanceContext { @@ -125,10 +133,21 @@ impl InstanceContext { } } +impl From for InstanceContext { + fn from(script_type: ScriptContextType) -> Self { + Self { + path_ignore_rules: Arc::new(Vec::new()), + script_type, + } + } +} + + impl Default for InstanceContext { fn default() -> Self { - InstanceContext { + Self { path_ignore_rules: Arc::new(Vec::new()), + script_type: ScriptContextType::Class, } } } diff --git a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__add_property.snap b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__add_property.snap index 9d5e9d778..288705b7b 100644 --- a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__add_property.snap +++ b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__add_property.snap @@ -12,6 +12,7 @@ properties: metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + script_type: Class children: [] diff --git a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_after_patch.snap b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_after_patch.snap index f8706912d..6fe548bc3 100644 --- a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_after_patch.snap +++ b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_after_patch.snap @@ -9,5 +9,6 @@ properties: {} metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + script_type: Class children: [] diff --git a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_initial.snap b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_initial.snap index 936658f1d..4e6989cee 100644 --- a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_initial.snap +++ b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_initial.snap @@ -12,6 +12,7 @@ properties: metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + script_type: Class children: [] diff --git a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__set_name_and_class_name.snap b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__set_name_and_class_name.snap index 634b4d641..d2c96c9da 100644 --- a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__set_name_and_class_name.snap +++ b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__set_name_and_class_name.snap @@ -9,5 +9,6 @@ properties: {} metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + script_type: Class children: [] diff --git a/src/snapshot/tests/snapshots/librojo__snapshot__tests__compute__add_child.snap b/src/snapshot/tests/snapshots/librojo__snapshot__tests__compute__add_child.snap index c4695b7c5..82389218d 100644 --- a/src/snapshot/tests/snapshots/librojo__snapshot__tests__compute__add_child.snap +++ b/src/snapshot/tests/snapshots/librojo__snapshot__tests__compute__add_child.snap @@ -10,7 +10,8 @@ added_instances: metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + script_type: Class name: New class_name: Folder properties: {} diff --git a/src/snapshot_middleware/csv.rs b/src/snapshot_middleware/csv.rs index 708f1bb8c..d59103f13 100644 --- a/src/snapshot_middleware/csv.rs +++ b/src/snapshot_middleware/csv.rs @@ -37,7 +37,7 @@ pub fn snapshot_csv( "Contents".to_owned() => table_contents.into(), }) .metadata( - InstanceMetadata::new() + InstanceMetadata::default() .instigating_source(path) .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]), ); diff --git a/src/snapshot_middleware/dir.rs b/src/snapshot_middleware/dir.rs index 092641e7f..b8a07e2c0 100644 --- a/src/snapshot_middleware/dir.rs +++ b/src/snapshot_middleware/dir.rs @@ -95,7 +95,7 @@ pub fn snapshot_dir_no_meta( .class_name("Folder") .children(snapshot_children) .metadata( - InstanceMetadata::new() + InstanceMetadata::default() .instigating_source(path) .relevant_paths(relevant_paths) .context(context), diff --git a/src/snapshot_middleware/json.rs b/src/snapshot_middleware/json.rs index 8c7f369e3..3fd211992 100644 --- a/src/snapshot_middleware/json.rs +++ b/src/snapshot_middleware/json.rs @@ -35,7 +35,7 @@ pub fn snapshot_json( .class_name("ModuleScript") .properties(properties) .metadata( - InstanceMetadata::new() + InstanceMetadata::default() .instigating_source(path) .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]) .context(context), diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 68a4fd222..636258cdb 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -1,7 +1,6 @@ -use std::{path::Path, str}; +use std::{path::Path, str, collections::HashMap}; -use anyhow::{Context}; -use maplit::hashmap; +use anyhow::Context; use memofs::{IoResultExt, Vfs}; use rbx_dom_weak::types::Enum; use serde::{Deserialize, Serialize}; @@ -14,7 +13,7 @@ use super::{ util::match_trailing, }; -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Default)] pub enum ScriptContextType { #[default] Class, @@ -36,7 +35,7 @@ pub fn snapshot_lua( ) -> anyhow::Result> { let file_name = path.file_name().unwrap().to_string_lossy(); - let is_run_context_enabled = true; //project.script_type == ScriptType::RunContext; + let is_run_context_enabled = context.script_type == ScriptContextType::RunContext; let run_context = &rbx_reflection_database::get().enums.get("RunContext").expect("Unable to get RunContext enums!").items; @@ -70,9 +69,8 @@ pub fn snapshot_lua( .with_context(|| format!("File was not valid UTF-8: {}", path.display()))? .to_owned(); - let mut properties = hashmap! { - "Source".to_owned() => contents_str.into(), - }; + let mut properties = HashMap::with_capacity(2); + properties.insert("Source".to_owned(), contents_str.into()); if let Some(run_context) = run_context { properties.insert("RunContext".to_owned(), Enum::from_u32(run_context.to_owned()).into()); @@ -85,10 +83,9 @@ pub fn snapshot_lua( .class_name(class_name) .properties(properties) .metadata( - InstanceMetadata::new() + InstanceMetadata::from(context) .instigating_source(path) .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]) - .context(context), ); if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? { @@ -141,6 +138,7 @@ pub fn snapshot_lua_init( mod test { use super::*; + use maplit::hashmap; use memofs::{InMemoryFs, VfsSnapshot}; #[test] @@ -152,11 +150,13 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = - snapshot_lua(&InstanceContext::default(), &mut vfs, Path::new("/foo.lua")) + snapshot_lua(&InstanceContext::from(ScriptContextType::Class), &mut vfs, Path::new("/foo.lua")) .unwrap() .unwrap(); - insta::assert_yaml_snapshot!(instance_snapshot); + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); } #[test] @@ -168,14 +168,16 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::default(), + &InstanceContext::from(ScriptContextType::Class), &mut vfs, Path::new("/foo.server.lua"), ) .unwrap() .unwrap(); - insta::assert_yaml_snapshot!(instance_snapshot); + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); } #[test] @@ -187,14 +189,16 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::default(), + &InstanceContext::from(ScriptContextType::Class), &mut vfs, Path::new("/foo.client.lua"), ) .unwrap() .unwrap(); - insta::assert_yaml_snapshot!(instance_snapshot); + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); } #[ignore = "init.lua functionality has moved to the root snapshot function"] @@ -212,11 +216,13 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = - snapshot_lua(&InstanceContext::default(), &mut vfs, Path::new("/root")) + snapshot_lua(&InstanceContext::from(ScriptContextType::Class), &mut vfs, Path::new("/root")) .unwrap() .unwrap(); - insta::assert_yaml_snapshot!(instance_snapshot); + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); } #[test] @@ -239,11 +245,13 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = - snapshot_lua(&InstanceContext::default(), &mut vfs, Path::new("/foo.lua")) + snapshot_lua(&InstanceContext::from(ScriptContextType::Class), &mut vfs, Path::new("/foo.lua")) .unwrap() .unwrap(); - insta::assert_yaml_snapshot!(instance_snapshot); + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); } #[test] @@ -266,14 +274,16 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::default(), + &InstanceContext::from(ScriptContextType::Class), &mut vfs, Path::new("/foo.server.lua"), ) .unwrap() .unwrap(); - insta::assert_yaml_snapshot!(instance_snapshot); + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); } #[test] @@ -298,7 +308,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::default(), + &InstanceContext::from(ScriptContextType::Class), &mut vfs, Path::new("/bar.server.lua"), ) diff --git a/src/snapshot_middleware/project.rs b/src/snapshot_middleware/project.rs index 2d54a1794..d559ab75a 100644 --- a/src/snapshot_middleware/project.rs +++ b/src/snapshot_middleware/project.rs @@ -77,7 +77,7 @@ pub fn snapshot_project_node( let name = Cow::Owned(instance_name.to_owned()); let mut properties = HashMap::new(); let mut children = Vec::new(); - let mut metadata = InstanceMetadata::default(); + let mut metadata = InstanceMetadata::from(context); if let Some(path_node) = &node.path { let path = path_node.path(); diff --git a/src/snapshot_middleware/rbxm.rs b/src/snapshot_middleware/rbxm.rs index 969f022dc..6b0834a84 100644 --- a/src/snapshot_middleware/rbxm.rs +++ b/src/snapshot_middleware/rbxm.rs @@ -26,7 +26,7 @@ pub fn snapshot_rbxm( let snapshot = InstanceSnapshot::from_tree(temp_tree, child) .name(name) .metadata( - InstanceMetadata::new() + InstanceMetadata::default() .instigating_source(path) .relevant_paths(vec![path.to_path_buf()]) .context(context), diff --git a/src/snapshot_middleware/rbxmx.rs b/src/snapshot_middleware/rbxmx.rs index 4f128ff6e..571254298 100644 --- a/src/snapshot_middleware/rbxmx.rs +++ b/src/snapshot_middleware/rbxmx.rs @@ -28,7 +28,7 @@ pub fn snapshot_rbxmx( let snapshot = InstanceSnapshot::from_tree(temp_tree, child) .name(name) .metadata( - InstanceMetadata::new() + InstanceMetadata::default() .instigating_source(path) .relevant_paths(vec![path.to_path_buf()]) .context(context), diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_from_vfs.snap index 11a8d81c0..379d7881b 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_from_vfs.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.csv - /foo.meta.json - context: {} + context: + script_type: Class name: foo class_name: LocalizationTable properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_with_meta.snap index eda826061..bceaf9a43 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_with_meta.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_with_meta.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.csv - /foo.meta.json - context: {} + context: + script_type: Class name: foo class_name: LocalizationTable properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__empty_folder.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__empty_folder.snap index e59da8db6..f2469410d 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__empty_folder.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__empty_folder.snap @@ -17,7 +17,8 @@ metadata: - /foo/init.client.lua - /foo/init.client.luau - /foo/init.csv - context: {} + context: + script_type: Class name: foo class_name: Folder properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__folder_in_folder.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__folder_in_folder.snap index 8c2ee9cc7..a596ebe81 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__folder_in_folder.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__folder_in_folder.snap @@ -17,7 +17,8 @@ metadata: - /foo/init.client.lua - /foo/init.client.luau - /foo/init.csv - context: {} + context: + script_type: Class name: foo class_name: Folder properties: {} @@ -37,7 +38,8 @@ children: - /foo/Child/init.client.lua - /foo/Child/init.client.luau - /foo/Child/init.csv - context: {} + context: + script_type: Class name: Child class_name: Folder properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json__test__instance_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json__test__instance_from_vfs.snap index b1cca7cb9..0cd2265f4 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json__test__instance_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json__test__instance_from_vfs.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.json - /foo.meta.json - context: {} + context: + script_type: Class name: foo class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs.snap index 5d4db1fcc..754acf3f3 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs.snap @@ -9,7 +9,8 @@ metadata: Path: /foo.model.json relevant_paths: - /foo.model.json - context: {} + context: + script_type: Class name: foo class_name: IntValue properties: @@ -20,7 +21,8 @@ children: metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + script_type: Class name: The Child class_name: StringValue properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs_legacy.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs_legacy.snap index 5d4db1fcc..754acf3f3 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs_legacy.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs_legacy.snap @@ -9,7 +9,8 @@ metadata: Path: /foo.model.json relevant_paths: - /foo.model.json - context: {} + context: + script_type: Class name: foo class_name: IntValue properties: @@ -20,7 +21,8 @@ children: metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + script_type: Class name: The Child class_name: StringValue properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__client_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__client_from_vfs.snap index 40b4bbe21..763c638c6 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__client_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__client_from_vfs.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.client.lua - /foo.meta.json - context: {} + context: + script_type: Class name: foo class_name: LocalScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__init_module_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__init_module_from_vfs.snap index 47340789e..0077f4c0e 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__init_module_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__init_module_from_vfs.snap @@ -13,7 +13,8 @@ metadata: - /root/init.lua - /root/init.server.lua - /root/init.client.lua - context: {} + context: + script_type: Class name: root class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__module_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__module_from_vfs.snap index 6877e9a92..e59bcda3c 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__module_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__module_from_vfs.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.lua - /foo.meta.json - context: {} + context: + script_type: Class name: foo class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__module_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__module_with_meta.snap index 8dcc57a97..e244cf2b2 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__module_with_meta.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__module_with_meta.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.lua - /foo.meta.json - context: {} + context: + script_type: Class name: foo class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__script_disabled.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__script_disabled.snap index 3f0408771..0717f0960 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__script_disabled.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__script_disabled.snap @@ -10,12 +10,15 @@ metadata: relevant_paths: - /bar.server.lua - /bar.meta.json - context: {} + context: + script_type: Class name: bar class_name: Script properties: Disabled: Bool: true + RunContext: + Enum: 0 Source: String: Hello there! children: [] diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__script_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__script_with_meta.snap index 6bdd2a385..14ba97be1 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__script_with_meta.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__script_with_meta.snap @@ -10,10 +10,13 @@ metadata: relevant_paths: - /foo.server.lua - /foo.meta.json - context: {} + context: + script_type: Class name: foo class_name: Script properties: + RunContext: + Enum: 0 Source: String: Hello there! children: [] diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__server_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__server_from_vfs.snap index 63d33a0a4..77e1eac47 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__server_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__server_from_vfs.snap @@ -10,10 +10,13 @@ metadata: relevant_paths: - /foo.server.lua - /foo.meta.json - context: {} + context: + script_type: Class name: foo class_name: Script properties: + RunContext: + Enum: 0 Source: String: Hello there! children: [] diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_from_direct_file.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_from_direct_file.snap index 795b14c17..a2bc5ec8a 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_from_direct_file.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_from_direct_file.snap @@ -9,7 +9,8 @@ metadata: Path: /foo/hello.project.json relevant_paths: - /foo/hello.project.json - context: {} + context: + script_type: Class name: direct-project class_name: Model properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_from_folder.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_from_folder.snap index d3a91f3c3..87aead098 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_from_folder.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_from_folder.snap @@ -9,7 +9,8 @@ metadata: Path: /foo/default.project.json relevant_paths: - /foo/default.project.json - context: {} + context: + script_type: Class name: indirect-project class_name: Folder properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_path_property_overrides.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_path_property_overrides.snap index 7427c9dcc..f5df1efe1 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_path_property_overrides.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_path_property_overrides.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo/other.project.json - /foo/default.project.json - context: {} + context: + script_type: Class name: path-property-override class_name: StringValue properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_children.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_children.snap index b50eb1be7..da1431671 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_children.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_children.snap @@ -9,7 +9,8 @@ metadata: Path: /foo.project.json relevant_paths: - /foo.project.json - context: {} + context: + script_type: Class name: children class_name: Folder properties: {} @@ -24,7 +25,8 @@ children: - $className: Model - Folder relevant_paths: [] - context: {} + context: + script_type: Class name: Child class_name: Model properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project.snap index d64a46e78..bb2a10d09 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo/other.project.json - /foo/default.project.json - context: {} + context: + script_type: Class name: path-project class_name: Model properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project_with_children.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project_with_children.snap index 0ceb043ab..a5f6dcb26 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project_with_children.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project_with_children.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo/other.project.json - /foo/default.project.json - context: {} + context: + script_type: Class name: path-child-project class_name: Folder properties: {} @@ -25,7 +26,8 @@ children: - $className: Model - Folder relevant_paths: [] - context: {} + context: + script_type: Class name: SomeChild class_name: Model properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_txt.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_txt.snap index 51a222f93..b0fb9b09a 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_txt.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_txt.snap @@ -11,7 +11,8 @@ metadata: - /foo/other.txt - /foo/other.meta.json - /foo/default.project.json - context: {} + context: + script_type: Class name: path-project class_name: StringValue properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_resolved_properties.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_resolved_properties.snap index 9b8e91efd..b03dbc514 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_resolved_properties.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_resolved_properties.snap @@ -9,7 +9,8 @@ metadata: Path: /foo.project.json relevant_paths: - /foo.project.json - context: {} + context: + script_type: Class name: resolved-properties class_name: StringValue properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_unresolved_properties.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_unresolved_properties.snap index a07300bba..7a8f3b225 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_unresolved_properties.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_unresolved_properties.snap @@ -9,7 +9,8 @@ metadata: Path: /foo.project.json relevant_paths: - /foo.project.json - context: {} + context: + script_type: Class name: unresolved-properties class_name: StringValue properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__toml__test__instance_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__toml__test__instance_from_vfs.snap index 3529bf896..32f9b8a9b 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__toml__test__instance_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__toml__test__instance_from_vfs.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.toml - /foo.meta.json - context: {} + context: + script_type: Class name: foo class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__txt__test__instance_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__txt__test__instance_from_vfs.snap index b8a8d4afe..0c5b88b5d 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__txt__test__instance_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__txt__test__instance_from_vfs.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.txt - /foo.meta.json - context: {} + context: + script_type: Class name: foo class_name: StringValue properties: diff --git a/src/snapshot_middleware/toml.rs b/src/snapshot_middleware/toml.rs index 6ee9be47e..e8e2c8b21 100644 --- a/src/snapshot_middleware/toml.rs +++ b/src/snapshot_middleware/toml.rs @@ -35,7 +35,7 @@ pub fn snapshot_toml( .class_name("ModuleScript") .properties(properties) .metadata( - InstanceMetadata::new() + InstanceMetadata::default() .instigating_source(path) .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]) .context(context), diff --git a/src/snapshot_middleware/txt.rs b/src/snapshot_middleware/txt.rs index 13d5b9907..397ec5098 100644 --- a/src/snapshot_middleware/txt.rs +++ b/src/snapshot_middleware/txt.rs @@ -31,7 +31,7 @@ pub fn snapshot_txt( .class_name("StringValue") .properties(properties) .metadata( - InstanceMetadata::new() + InstanceMetadata::default() .instigating_source(path) .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]) .context(context), From da2342be87f1cc1192a4ccbe8883b00cdd705a75 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Fri, 4 Aug 2023 20:01:56 +1000 Subject: [PATCH 06/22] Update Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4e2803a9..b53d81f06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ * Add new plugin template to the `init` command ([#738]) * Added rich Source diffs in patch visualizer ([#748]) * Fix PatchTree performance issues ([#755]) +* A `$scriptType` field has been added to the project.json schema, allowing for scripts to be differentiated as lasses or through RunContext ([#765]). [#745]: https://github.com/rojo-rbx/rojo/pull/745 [#668]: https://github.com/rojo-rbx/rojo/pull/668 @@ -46,6 +47,7 @@ [#738]: https://github.com/rojo-rbx/rojo/pull/738 [#748]: https://github.com/rojo-rbx/rojo/pull/748 [#755]: https://github.com/rojo-rbx/rojo/pull/755 +[#765]: https://github.com/rojo-rbx/rojo/pull/765 ## [7.3.0] - April 22, 2023 * Added `$attributes` to project format. ([#574]) From 2f420f5b148aead160490ce80b9c9a5c77bedd0b Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Sat, 5 Aug 2023 07:58:55 +1000 Subject: [PATCH 07/22] Remove Submodule Changes --- plugin/modules/flipper | 1 - plugin/modules/promise | 1 - plugin/modules/roact | 1 - plugin/modules/t | 1 - plugin/modules/testez | 1 - 5 files changed, 5 deletions(-) delete mode 160000 plugin/modules/flipper delete mode 160000 plugin/modules/promise delete mode 160000 plugin/modules/roact delete mode 160000 plugin/modules/t delete mode 160000 plugin/modules/testez diff --git a/plugin/modules/flipper b/plugin/modules/flipper deleted file mode 160000 index 4cf7a03cb..000000000 --- a/plugin/modules/flipper +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4cf7a03cb6776ec0af41b6a50988aa70e5c9cc3c diff --git a/plugin/modules/promise b/plugin/modules/promise deleted file mode 160000 index 7fb09d103..000000000 --- a/plugin/modules/promise +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7fb09d103f4a680cbd61d5348ec9c5d50244a8e0 diff --git a/plugin/modules/roact b/plugin/modules/roact deleted file mode 160000 index f7d2f1ce1..000000000 --- a/plugin/modules/roact +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f7d2f1ce1dd69120f457c2f8032bb184eb8f0c29 diff --git a/plugin/modules/t b/plugin/modules/t deleted file mode 160000 index f643b5068..000000000 --- a/plugin/modules/t +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f643b50682c24ec8d6ac3e11f41ee8cbbb2bcecb diff --git a/plugin/modules/testez b/plugin/modules/testez deleted file mode 160000 index 25d957d4d..000000000 --- a/plugin/modules/testez +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 25d957d4d5c4c02a52843ef43e72f21f973c2908 From 6475a624f34ba63b6d651d00cf742147260fa0f6 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Sat, 5 Aug 2023 07:59:53 +1000 Subject: [PATCH 08/22] chore: rustfmt --- src/snapshot/metadata.rs | 5 ++-- src/snapshot_middleware/lua.rs | 48 ++++++++++++++++++++++------------ src/snapshot_middleware/mod.rs | 2 +- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/snapshot/metadata.rs b/src/snapshot/metadata.rs index b18b06df1..6a9a67754 100644 --- a/src/snapshot/metadata.rs +++ b/src/snapshot/metadata.rs @@ -6,7 +6,9 @@ use std::{ use serde::{Deserialize, Serialize}; -use crate::{glob::Glob, path_serializer, project::ProjectNode, snapshot_middleware::ScriptContextType}; +use crate::{ + glob::Glob, path_serializer, project::ProjectNode, snapshot_middleware::ScriptContextType, +}; /// Rojo-specific metadata that can be associated with an instance or a snapshot /// of an instance. @@ -142,7 +144,6 @@ impl From for InstanceContext { } } - impl Default for InstanceContext { fn default() -> Self { Self { diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 636258cdb..7f90b268a 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -1,4 +1,4 @@ -use std::{path::Path, str, collections::HashMap}; +use std::{collections::HashMap, path::Path, str}; use anyhow::Context; use memofs::{IoResultExt, Vfs}; @@ -37,7 +37,11 @@ pub fn snapshot_lua( let is_run_context_enabled = context.script_type == ScriptContextType::RunContext; - let run_context = &rbx_reflection_database::get().enums.get("RunContext").expect("Unable to get RunContext enums!").items; + let run_context = &rbx_reflection_database::get() + .enums + .get("RunContext") + .expect("Unable to get RunContext enums!") + .items; let (script_type, instance_name) = if let Some(name) = match_trailing(&file_name, ".server.lua") { @@ -73,7 +77,10 @@ pub fn snapshot_lua( properties.insert("Source".to_owned(), contents_str.into()); if let Some(run_context) = run_context { - properties.insert("RunContext".to_owned(), Enum::from_u32(run_context.to_owned()).into()); + properties.insert( + "RunContext".to_owned(), + Enum::from_u32(run_context.to_owned()).into(), + ); } let meta_path = path.with_file_name(format!("{}.meta.json", instance_name)); @@ -85,7 +92,7 @@ pub fn snapshot_lua( .metadata( InstanceMetadata::from(context) .instigating_source(path) - .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]) + .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]), ); if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? { @@ -149,10 +156,13 @@ mod test { let mut vfs = Vfs::new(imfs); - let instance_snapshot = - snapshot_lua(&InstanceContext::from(ScriptContextType::Class), &mut vfs, Path::new("/foo.lua")) - .unwrap() - .unwrap(); + let instance_snapshot = snapshot_lua( + &InstanceContext::from(ScriptContextType::Class), + &mut vfs, + Path::new("/foo.lua"), + ) + .unwrap() + .unwrap(); insta::with_settings!({ sort_maps => true }, { insta::assert_yaml_snapshot!(instance_snapshot); @@ -215,10 +225,13 @@ mod test { let mut vfs = Vfs::new(imfs); - let instance_snapshot = - snapshot_lua(&InstanceContext::from(ScriptContextType::Class), &mut vfs, Path::new("/root")) - .unwrap() - .unwrap(); + let instance_snapshot = snapshot_lua( + &InstanceContext::from(ScriptContextType::Class), + &mut vfs, + Path::new("/root"), + ) + .unwrap() + .unwrap(); insta::with_settings!({ sort_maps => true }, { insta::assert_yaml_snapshot!(instance_snapshot); @@ -244,10 +257,13 @@ mod test { let mut vfs = Vfs::new(imfs); - let instance_snapshot = - snapshot_lua(&InstanceContext::from(ScriptContextType::Class), &mut vfs, Path::new("/foo.lua")) - .unwrap() - .unwrap(); + let instance_snapshot = snapshot_lua( + &InstanceContext::from(ScriptContextType::Class), + &mut vfs, + Path::new("/foo.lua"), + ) + .unwrap() + .unwrap(); insta::with_settings!({ sort_maps => true }, { insta::assert_yaml_snapshot!(instance_snapshot); diff --git a/src/snapshot_middleware/mod.rs b/src/snapshot_middleware/mod.rs index 87b1ccfc8..cb079cc6c 100644 --- a/src/snapshot_middleware/mod.rs +++ b/src/snapshot_middleware/mod.rs @@ -38,7 +38,7 @@ use self::{ util::PathExt, }; -pub use self::{project::snapshot_project_node, lua::ScriptContextType}; +pub use self::{lua::ScriptContextType, project::snapshot_project_node}; /// The main entrypoint to the snapshot function. This function can be pointed /// at any path and will return something if Rojo knows how to deal with it. From 9d20fce9ad1db0077948725baaafcc45c8d51cc3 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Sat, 5 Aug 2023 08:27:02 +1000 Subject: [PATCH 09/22] Fix failing e2e tests --- ...d__tests__build__script_meta_disabled.snap | 1 + ...o_end__tests__build__server_in_folder.snap | 1 + ...end_to_end__tests__build__server_init.snap | 1 + ...d_to_end__tests__serve__scripts_all-2.snap | 2 ++ ...end_to_end__tests__serve__scripts_all.snap | 2 ++ tests/tests/serve.rs | 22 +++++++++++-------- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/rojo-test/build-test-snapshots/end_to_end__tests__build__script_meta_disabled.snap b/rojo-test/build-test-snapshots/end_to_end__tests__build__script_meta_disabled.snap index 0876056e2..28354bd64 100644 --- a/rojo-test/build-test-snapshots/end_to_end__tests__build__script_meta_disabled.snap +++ b/rojo-test/build-test-snapshots/end_to_end__tests__build__script_meta_disabled.snap @@ -11,6 +11,7 @@ expression: contents hello true + 0 -- This script should be marked 'Disabled' diff --git a/rojo-test/build-test-snapshots/end_to_end__tests__build__server_in_folder.snap b/rojo-test/build-test-snapshots/end_to_end__tests__build__server_in_folder.snap index 282889d0f..c9806d005 100644 --- a/rojo-test/build-test-snapshots/end_to_end__tests__build__server_in_folder.snap +++ b/rojo-test/build-test-snapshots/end_to_end__tests__build__server_in_folder.snap @@ -10,6 +10,7 @@ expression: contents serverScript + 0 -- This is a Lua server script diff --git a/rojo-test/build-test-snapshots/end_to_end__tests__build__server_init.snap b/rojo-test/build-test-snapshots/end_to_end__tests__build__server_init.snap index 070b7012a..5858d5e01 100644 --- a/rojo-test/build-test-snapshots/end_to_end__tests__build__server_init.snap +++ b/rojo-test/build-test-snapshots/end_to_end__tests__build__server_init.snap @@ -6,6 +6,7 @@ expression: contents server_init + 0 return "From folder/init.server.lua" diff --git a/rojo-test/serve-test-snapshots/end_to_end__tests__serve__scripts_all-2.snap b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__scripts_all-2.snap index 78dcebea3..49d8148b3 100644 --- a/rojo-test/serve-test-snapshots/end_to_end__tests__serve__scripts_all-2.snap +++ b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__scripts_all-2.snap @@ -24,6 +24,8 @@ instances: Name: bar Parent: id-2 Properties: + RunContext: + Enum: 0 Source: String: "-- Hello, from bar!" id-4: diff --git a/rojo-test/serve-test-snapshots/end_to_end__tests__serve__scripts_all.snap b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__scripts_all.snap index 52efebac4..62e5ceeff 100644 --- a/rojo-test/serve-test-snapshots/end_to_end__tests__serve__scripts_all.snap +++ b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__scripts_all.snap @@ -24,6 +24,8 @@ instances: Name: bar Parent: id-2 Properties: + RunContext: + Enum: 0 Source: String: "-- Hello, from bar!" id-4: diff --git a/tests/tests/serve.rs b/tests/tests/serve.rs index 9cca9fac1..d55d339bb 100644 --- a/tests/tests/serve.rs +++ b/tests/tests/serve.rs @@ -1,6 +1,6 @@ use std::fs; -use insta::assert_yaml_snapshot; +use insta::{assert_yaml_snapshot, with_settings}; use tempfile::tempdir; use crate::rojo_test::{internable::InternAndRedact, serve_util::run_serve_test}; @@ -30,10 +30,12 @@ fn scripts() { assert_yaml_snapshot!("scripts_info", redactions.redacted_yaml(info)); let read_response = session.get_api_read(root_id).unwrap(); - assert_yaml_snapshot!( - "scripts_all", - read_response.intern_and_redact(&mut redactions, root_id) - ); + with_settings!({ sort_maps => true }, { + assert_yaml_snapshot!( + "scripts_all", + read_response.intern_and_redact(&mut redactions, root_id) + ); + }); fs::write(session.path().join("src/foo.lua"), "Updated foo!").unwrap(); @@ -44,10 +46,12 @@ fn scripts() { ); let read_response = session.get_api_read(root_id).unwrap(); - assert_yaml_snapshot!( - "scripts_all-2", - read_response.intern_and_redact(&mut redactions, root_id) - ); + with_settings!({ sort_maps => true }, { + assert_yaml_snapshot!( + "scripts_all-2", + read_response.intern_and_redact(&mut redactions, root_id) + ); + }); }); } From 45f0d316b5a311d7a43315a72811c6b2b1687925 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Tue, 8 Aug 2023 18:36:04 +1000 Subject: [PATCH 10/22] Refactor Constructors --- src/snapshot/instance_snapshot.rs | 4 +-- src/snapshot/metadata.rs | 41 ++++++++++++++---------------- src/snapshot_middleware/csv.rs | 2 +- src/snapshot_middleware/dir.rs | 2 +- src/snapshot_middleware/json.rs | 2 +- src/snapshot_middleware/lua.rs | 3 ++- src/snapshot_middleware/project.rs | 2 +- src/snapshot_middleware/rbxm.rs | 2 +- src/snapshot_middleware/rbxmx.rs | 2 +- src/snapshot_middleware/toml.rs | 2 +- src/snapshot_middleware/txt.rs | 2 +- 11 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/snapshot/instance_snapshot.rs b/src/snapshot/instance_snapshot.rs index 0b3a4fca3..ed707f536 100644 --- a/src/snapshot/instance_snapshot.rs +++ b/src/snapshot/instance_snapshot.rs @@ -42,7 +42,7 @@ impl InstanceSnapshot { pub fn new() -> Self { Self { snapshot_id: Ref::none(), - metadata: InstanceMetadata::default(), + metadata: InstanceMetadata::new(), name: Cow::Borrowed("DEFAULT"), class_name: Cow::Borrowed("DEFAULT"), properties: HashMap::new(), @@ -120,7 +120,7 @@ impl InstanceSnapshot { Self { snapshot_id: id, - metadata: InstanceMetadata::default(), + metadata: InstanceMetadata::new(), name: Cow::Owned(instance.name), class_name: Cow::Owned(instance.class), properties: instance.properties, diff --git a/src/snapshot/metadata.rs b/src/snapshot/metadata.rs index 6a9a67754..f2f771dc6 100644 --- a/src/snapshot/metadata.rs +++ b/src/snapshot/metadata.rs @@ -57,6 +57,15 @@ pub struct InstanceMetadata { } impl InstanceMetadata { + pub fn new() -> Self { + Self { + ignore_unknown_instances: false, + instigating_source: None, + relevant_paths: Vec::new(), + context: InstanceContext::new(), + } + } + pub fn ignore_unknown_instances(self, ignore_unknown_instances: bool) -> Self { Self { ignore_unknown_instances, @@ -86,25 +95,9 @@ impl InstanceMetadata { } } -impl From<&InstanceContext> for InstanceMetadata { - fn from(context: &InstanceContext) -> Self { - Self { - ignore_unknown_instances: false, - instigating_source: None, - relevant_paths: Vec::new(), - context: context.to_owned(), - } - } -} - impl Default for InstanceMetadata { fn default() -> Self { - Self { - ignore_unknown_instances: false, - instigating_source: None, - relevant_paths: Vec::new(), - context: InstanceContext::from(ScriptContextType::Class), - } + Self::new() } } @@ -116,6 +109,13 @@ pub struct InstanceContext { } impl InstanceContext { + pub fn new() -> Self { + Self { + path_ignore_rules: Arc::new(Vec::new()), + script_type: ScriptContextType::Class, + } + } + /// Extend the list of ignore rules in the context with the given new rules. pub fn add_path_ignore_rules(&mut self, new_rules: I) where @@ -138,18 +138,15 @@ impl InstanceContext { impl From for InstanceContext { fn from(script_type: ScriptContextType) -> Self { Self { - path_ignore_rules: Arc::new(Vec::new()), script_type, + ..Self::new() } } } impl Default for InstanceContext { fn default() -> Self { - Self { - path_ignore_rules: Arc::new(Vec::new()), - script_type: ScriptContextType::Class, - } + Self::new() } } diff --git a/src/snapshot_middleware/csv.rs b/src/snapshot_middleware/csv.rs index d59103f13..708f1bb8c 100644 --- a/src/snapshot_middleware/csv.rs +++ b/src/snapshot_middleware/csv.rs @@ -37,7 +37,7 @@ pub fn snapshot_csv( "Contents".to_owned() => table_contents.into(), }) .metadata( - InstanceMetadata::default() + InstanceMetadata::new() .instigating_source(path) .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]), ); diff --git a/src/snapshot_middleware/dir.rs b/src/snapshot_middleware/dir.rs index b8a07e2c0..092641e7f 100644 --- a/src/snapshot_middleware/dir.rs +++ b/src/snapshot_middleware/dir.rs @@ -95,7 +95,7 @@ pub fn snapshot_dir_no_meta( .class_name("Folder") .children(snapshot_children) .metadata( - InstanceMetadata::default() + InstanceMetadata::new() .instigating_source(path) .relevant_paths(relevant_paths) .context(context), diff --git a/src/snapshot_middleware/json.rs b/src/snapshot_middleware/json.rs index 3fd211992..8c7f369e3 100644 --- a/src/snapshot_middleware/json.rs +++ b/src/snapshot_middleware/json.rs @@ -35,7 +35,7 @@ pub fn snapshot_json( .class_name("ModuleScript") .properties(properties) .metadata( - InstanceMetadata::default() + InstanceMetadata::new() .instigating_source(path) .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]) .context(context), diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 7f90b268a..56ebef84c 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -90,7 +90,8 @@ pub fn snapshot_lua( .class_name(class_name) .properties(properties) .metadata( - InstanceMetadata::from(context) + InstanceMetadata::new() + .context(context) .instigating_source(path) .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]), ); diff --git a/src/snapshot_middleware/project.rs b/src/snapshot_middleware/project.rs index d559ab75a..ad39aba5a 100644 --- a/src/snapshot_middleware/project.rs +++ b/src/snapshot_middleware/project.rs @@ -77,7 +77,7 @@ pub fn snapshot_project_node( let name = Cow::Owned(instance_name.to_owned()); let mut properties = HashMap::new(); let mut children = Vec::new(); - let mut metadata = InstanceMetadata::from(context); + let mut metadata = InstanceMetadata::new().context(context); if let Some(path_node) = &node.path { let path = path_node.path(); diff --git a/src/snapshot_middleware/rbxm.rs b/src/snapshot_middleware/rbxm.rs index 6b0834a84..969f022dc 100644 --- a/src/snapshot_middleware/rbxm.rs +++ b/src/snapshot_middleware/rbxm.rs @@ -26,7 +26,7 @@ pub fn snapshot_rbxm( let snapshot = InstanceSnapshot::from_tree(temp_tree, child) .name(name) .metadata( - InstanceMetadata::default() + InstanceMetadata::new() .instigating_source(path) .relevant_paths(vec![path.to_path_buf()]) .context(context), diff --git a/src/snapshot_middleware/rbxmx.rs b/src/snapshot_middleware/rbxmx.rs index 571254298..4f128ff6e 100644 --- a/src/snapshot_middleware/rbxmx.rs +++ b/src/snapshot_middleware/rbxmx.rs @@ -28,7 +28,7 @@ pub fn snapshot_rbxmx( let snapshot = InstanceSnapshot::from_tree(temp_tree, child) .name(name) .metadata( - InstanceMetadata::default() + InstanceMetadata::new() .instigating_source(path) .relevant_paths(vec![path.to_path_buf()]) .context(context), diff --git a/src/snapshot_middleware/toml.rs b/src/snapshot_middleware/toml.rs index e8e2c8b21..6ee9be47e 100644 --- a/src/snapshot_middleware/toml.rs +++ b/src/snapshot_middleware/toml.rs @@ -35,7 +35,7 @@ pub fn snapshot_toml( .class_name("ModuleScript") .properties(properties) .metadata( - InstanceMetadata::default() + InstanceMetadata::new() .instigating_source(path) .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]) .context(context), diff --git a/src/snapshot_middleware/txt.rs b/src/snapshot_middleware/txt.rs index 397ec5098..13d5b9907 100644 --- a/src/snapshot_middleware/txt.rs +++ b/src/snapshot_middleware/txt.rs @@ -31,7 +31,7 @@ pub fn snapshot_txt( .class_name("StringValue") .properties(properties) .metadata( - InstanceMetadata::default() + InstanceMetadata::new() .instigating_source(path) .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]) .context(context), From a473d72387826fbcb77c2fb083731115433d738b Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Sat, 12 Aug 2023 09:51:49 +1000 Subject: [PATCH 11/22] Minor Changes [skip ci] --- src/snapshot/instance_snapshot.rs | 4 ++-- src/snapshot/metadata.rs | 2 +- src/snapshot_middleware/lua.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/snapshot/instance_snapshot.rs b/src/snapshot/instance_snapshot.rs index ed707f536..0b3a4fca3 100644 --- a/src/snapshot/instance_snapshot.rs +++ b/src/snapshot/instance_snapshot.rs @@ -42,7 +42,7 @@ impl InstanceSnapshot { pub fn new() -> Self { Self { snapshot_id: Ref::none(), - metadata: InstanceMetadata::new(), + metadata: InstanceMetadata::default(), name: Cow::Borrowed("DEFAULT"), class_name: Cow::Borrowed("DEFAULT"), properties: HashMap::new(), @@ -120,7 +120,7 @@ impl InstanceSnapshot { Self { snapshot_id: id, - metadata: InstanceMetadata::new(), + metadata: InstanceMetadata::default(), name: Cow::Owned(instance.name), class_name: Cow::Owned(instance.class), properties: instance.properties, diff --git a/src/snapshot/metadata.rs b/src/snapshot/metadata.rs index f2f771dc6..a879bc414 100644 --- a/src/snapshot/metadata.rs +++ b/src/snapshot/metadata.rs @@ -62,7 +62,7 @@ impl InstanceMetadata { ignore_unknown_instances: false, instigating_source: None, relevant_paths: Vec::new(), - context: InstanceContext::new(), + context: InstanceContext::default(), } } diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 56ebef84c..99de46298 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -91,9 +91,9 @@ pub fn snapshot_lua( .properties(properties) .metadata( InstanceMetadata::new() - .context(context) .instigating_source(path) - .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]), + .relevant_paths(vec![path.to_path_buf(), meta_path.clone()]) + .context(context), ); if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? { From a3f133bce528974804c5da827635a4a8304106df Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Sat, 9 Sep 2023 14:58:15 +1000 Subject: [PATCH 12/22] chore: review comments --- src/project.rs | 4 ++-- src/snapshot/metadata.rs | 11 +++++++++++ src/snapshot_middleware/lua.rs | 12 ++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/project.rs b/src/project.rs index a2831c760..bcd123c14 100644 --- a/src/project.rs +++ b/src/project.rs @@ -76,8 +76,8 @@ pub struct Project { /// The mode to use when mapping scripts into Roblox. /// Can be either `Class` or `RunContext` and determines whether script /// behavior is set using the `RunContext` property or the script's `ClassName`. - #[serde(default)] - pub script_type: ScriptContextType, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub script_type: Option, /// A list of globs, relative to the folder the project file is in, that /// match files that should be excluded if Rojo encounters them. diff --git a/src/snapshot/metadata.rs b/src/snapshot/metadata.rs index a879bc414..52f88df9f 100644 --- a/src/snapshot/metadata.rs +++ b/src/snapshot/metadata.rs @@ -135,6 +135,8 @@ impl InstanceContext { } } +// serve_session always passes an option from the config file, but tests want it to be explict +#[cfg(test)] impl From for InstanceContext { fn from(script_type: ScriptContextType) -> Self { Self { @@ -144,6 +146,15 @@ impl From for InstanceContext { } } +impl From> for InstanceContext { + fn from(script_type: Option) -> Self { + Self { + script_type: script_type.unwrap_or_default(), + ..Self::new() + } + } +} + impl Default for InstanceContext { fn default() -> Self { Self::new() diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 99de46298..013f95205 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -35,9 +35,7 @@ pub fn snapshot_lua( ) -> anyhow::Result> { let file_name = path.file_name().unwrap().to_string_lossy(); - let is_run_context_enabled = context.script_type == ScriptContextType::RunContext; - - let run_context = &rbx_reflection_database::get() + let run_context_enums = &rbx_reflection_database::get() .enums .get("RunContext") .expect("Unable to get RunContext enums!") @@ -60,10 +58,12 @@ pub fn snapshot_lua( return Ok(None); }; + let is_run_context_enabled = context.script_type == ScriptContextType::RunContext; + let (class_name, run_context) = match (is_run_context_enabled, script_type) { - (true, ScriptType::Server) => ("Script", run_context.get("Server")), - (true, ScriptType::Client) => ("Script", run_context.get("Client")), - (false, ScriptType::Server) => ("Script", run_context.get("Legacy")), + (true, ScriptType::Server) => ("Script", run_context_enums.get("Server")), + (true, ScriptType::Client) => ("Script", run_context_enums.get("Client")), + (false, ScriptType::Server) => ("Script", run_context_enums.get("Legacy")), (false, ScriptType::Client) => ("LocalScript", None), (_, ScriptType::Module) => ("ModuleScript", None), }; From e718934ab0da32b29cb609445c75d3feedd7f2b2 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Sat, 9 Sep 2023 15:47:49 +1000 Subject: [PATCH 13/22] tests: add snapshot tests --- src/snapshot_middleware/lua.rs | 173 +++++++++++++++++- ...re__lua__test__class_client_from_vfs.snap} | 0 ...re__lua__test__class_module_from_vfs.snap} | 0 ...e__lua__test__class_module_with_meta.snap} | 0 ...re__lua__test__class_script_disabled.snap} | 0 ...e__lua__test__class_script_with_meta.snap} | 0 ...re__lua__test__class_server_from_vfs.snap} | 0 ...lua__test__runcontext_client_from_vfs.snap | 23 +++ ...lua__test__runcontext_module_from_vfs.snap | 21 +++ ...ua__test__runcontext_module_with_meta.snap | 21 +++ ...lua__test__runcontext_script_disabled.snap | 25 +++ ...ua__test__runcontext_script_with_meta.snap | 23 +++ ...lua__test__runcontext_server_from_vfs.snap | 23 +++ 13 files changed, 303 insertions(+), 6 deletions(-) rename src/snapshot_middleware/snapshots/{librojo__snapshot_middleware__lua__test__client_from_vfs.snap => librojo__snapshot_middleware__lua__test__class_client_from_vfs.snap} (100%) rename src/snapshot_middleware/snapshots/{librojo__snapshot_middleware__lua__test__module_from_vfs.snap => librojo__snapshot_middleware__lua__test__class_module_from_vfs.snap} (100%) rename src/snapshot_middleware/snapshots/{librojo__snapshot_middleware__lua__test__module_with_meta.snap => librojo__snapshot_middleware__lua__test__class_module_with_meta.snap} (100%) rename src/snapshot_middleware/snapshots/{librojo__snapshot_middleware__lua__test__script_disabled.snap => librojo__snapshot_middleware__lua__test__class_script_disabled.snap} (100%) rename src/snapshot_middleware/snapshots/{librojo__snapshot_middleware__lua__test__script_with_meta.snap => librojo__snapshot_middleware__lua__test__class_script_with_meta.snap} (100%) rename src/snapshot_middleware/snapshots/{librojo__snapshot_middleware__lua__test__server_from_vfs.snap => librojo__snapshot_middleware__lua__test__class_server_from_vfs.snap} (100%) create mode 100644 src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_client_from_vfs.snap create mode 100644 src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_from_vfs.snap create mode 100644 src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_with_meta.snap create mode 100644 src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_disabled.snap create mode 100644 src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_with_meta.snap create mode 100644 src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_server_from_vfs.snap diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 013f95205..dbe67d89e 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -150,7 +150,7 @@ mod test { use memofs::{InMemoryFs, VfsSnapshot}; #[test] - fn module_from_vfs() { + fn class_module_from_vfs() { let mut imfs = InMemoryFs::new(); imfs.load_snapshot("/foo.lua", VfsSnapshot::file("Hello there!")) .unwrap(); @@ -171,7 +171,28 @@ mod test { } #[test] - fn server_from_vfs() { + fn runcontext_module_from_vfs() { + let mut imfs = InMemoryFs::new(); + imfs.load_snapshot("/foo.lua", VfsSnapshot::file("Hello there!")) + .unwrap(); + + let mut vfs = Vfs::new(imfs); + + let instance_snapshot = snapshot_lua( + &InstanceContext::from(ScriptContextType::RunContext), + &mut vfs, + Path::new("/foo.lua"), + ) + .unwrap() + .unwrap(); + + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); + } + + #[test] + fn class_server_from_vfs() { let mut imfs = InMemoryFs::new(); imfs.load_snapshot("/foo.server.lua", VfsSnapshot::file("Hello there!")) .unwrap(); @@ -192,7 +213,28 @@ mod test { } #[test] - fn client_from_vfs() { + fn runcontext_server_from_vfs() { + let mut imfs = InMemoryFs::new(); + imfs.load_snapshot("/foo.server.lua", VfsSnapshot::file("Hello there!")) + .unwrap(); + + let mut vfs = Vfs::new(imfs); + + let instance_snapshot = snapshot_lua( + &InstanceContext::from(ScriptContextType::RunContext), + &mut vfs, + Path::new("/foo.server.lua"), + ) + .unwrap() + .unwrap(); + + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); + } + + #[test] + fn class_client_from_vfs() { let mut imfs = InMemoryFs::new(); imfs.load_snapshot("/foo.client.lua", VfsSnapshot::file("Hello there!")) .unwrap(); @@ -212,6 +254,27 @@ mod test { }); } + #[test] + fn runcontext_client_from_vfs() { + let mut imfs = InMemoryFs::new(); + imfs.load_snapshot("/foo.client.lua", VfsSnapshot::file("Hello there!")) + .unwrap(); + + let mut vfs = Vfs::new(imfs); + + let instance_snapshot = snapshot_lua( + &InstanceContext::from(ScriptContextType::RunContext), + &mut vfs, + Path::new("/foo.client.lua"), + ) + .unwrap() + .unwrap(); + + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); + } + #[ignore = "init.lua functionality has moved to the root snapshot function"] #[test] fn init_module_from_vfs() { @@ -240,7 +303,7 @@ mod test { } #[test] - fn module_with_meta() { + fn class_module_with_meta() { let mut imfs = InMemoryFs::new(); imfs.load_snapshot("/foo.lua", VfsSnapshot::file("Hello there!")) .unwrap(); @@ -272,7 +335,39 @@ mod test { } #[test] - fn script_with_meta() { + 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 mut vfs = Vfs::new(imfs); + + let instance_snapshot = snapshot_lua( + &InstanceContext::from(ScriptContextType::RunContext), + &mut vfs, + Path::new("/foo.lua"), + ) + .unwrap() + .unwrap(); + + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); + } + + #[test] + fn class_script_with_meta() { let mut imfs = InMemoryFs::new(); imfs.load_snapshot("/foo.server.lua", VfsSnapshot::file("Hello there!")) .unwrap(); @@ -304,7 +399,39 @@ mod test { } #[test] - fn script_disabled() { + 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 mut vfs = Vfs::new(imfs); + + let instance_snapshot = snapshot_lua( + &InstanceContext::from(ScriptContextType::RunContext), + &mut vfs, + Path::new("/foo.server.lua"), + ) + .unwrap() + .unwrap(); + + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); + } + + #[test] + fn class_script_disabled() { let mut imfs = InMemoryFs::new(); imfs.load_snapshot("/bar.server.lua", VfsSnapshot::file("Hello there!")) .unwrap(); @@ -336,4 +463,38 @@ mod test { 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 mut vfs = Vfs::new(imfs); + + let instance_snapshot = snapshot_lua( + &InstanceContext::from(ScriptContextType::RunContext), + &mut vfs, + Path::new("/bar.server.lua"), + ) + .unwrap() + .unwrap(); + + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); + } } diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__client_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_client_from_vfs.snap similarity index 100% rename from src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__client_from_vfs.snap rename to src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_client_from_vfs.snap diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__module_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_module_from_vfs.snap similarity index 100% rename from src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__module_from_vfs.snap rename to src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_module_from_vfs.snap diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__module_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_module_with_meta.snap similarity index 100% rename from src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__module_with_meta.snap rename to src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_module_with_meta.snap diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__script_disabled.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_script_disabled.snap similarity index 100% rename from src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__script_disabled.snap rename to src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_script_disabled.snap diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__script_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_script_with_meta.snap similarity index 100% rename from src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__script_with_meta.snap rename to src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_script_with_meta.snap diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__server_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_server_from_vfs.snap similarity index 100% rename from src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__server_from_vfs.snap rename to src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_server_from_vfs.snap diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_client_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_client_from_vfs.snap new file mode 100644 index 000000000..e1873aa8f --- /dev/null +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_client_from_vfs.snap @@ -0,0 +1,23 @@ +--- +source: src/snapshot_middleware/lua.rs +expression: instance_snapshot +--- +snapshot_id: "00000000000000000000000000000000" +metadata: + ignore_unknown_instances: false + instigating_source: + Path: /foo.client.lua + relevant_paths: + - /foo.client.lua + - /foo.meta.json + context: + script_type: RunContext +name: foo +class_name: Script +properties: + RunContext: + Enum: 2 + Source: + String: Hello there! +children: [] + diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_from_vfs.snap new file mode 100644 index 000000000..1c8fb22bc --- /dev/null +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_from_vfs.snap @@ -0,0 +1,21 @@ +--- +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 + context: + script_type: RunContext +name: foo +class_name: ModuleScript +properties: + Source: + String: Hello there! +children: [] + diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_with_meta.snap new file mode 100644 index 000000000..e5b7e36d7 --- /dev/null +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_with_meta.snap @@ -0,0 +1,21 @@ +--- +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 + context: + script_type: RunContext +name: foo +class_name: ModuleScript +properties: + Source: + String: Hello there! +children: [] + diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_disabled.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_disabled.snap new file mode 100644 index 000000000..38f8ab7b4 --- /dev/null +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_disabled.snap @@ -0,0 +1,25 @@ +--- +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 + context: + script_type: RunContext +name: bar +class_name: Script +properties: + Disabled: + Bool: true + RunContext: + Enum: 1 + Source: + String: Hello there! +children: [] + diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_with_meta.snap new file mode 100644 index 000000000..0e0f27520 --- /dev/null +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_with_meta.snap @@ -0,0 +1,23 @@ +--- +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 + context: + script_type: RunContext +name: foo +class_name: Script +properties: + RunContext: + Enum: 1 + Source: + String: Hello there! +children: [] + diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_server_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_server_from_vfs.snap new file mode 100644 index 000000000..9bdf4e055 --- /dev/null +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_server_from_vfs.snap @@ -0,0 +1,23 @@ +--- +source: src/snapshot_middleware/lua.rs +expression: instance_snapshot +--- +snapshot_id: "00000000000000000000000000000000" +metadata: + ignore_unknown_instances: false + instigating_source: + Path: /foo.server.lua + relevant_paths: + - /foo.server.lua + - /foo.meta.json + context: + script_type: RunContext +name: foo +class_name: Script +properties: + RunContext: + Enum: 1 + Source: + String: Hello there! +children: [] + From 9eb0062cd310e54ba239f7070200f43a2a5bffac Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Sat, 9 Sep 2023 16:27:10 +1000 Subject: [PATCH 14/22] fix: support nested `project.json` files --- src/snapshot/metadata.rs | 4 ++++ src/snapshot_middleware/project.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/src/snapshot/metadata.rs b/src/snapshot/metadata.rs index 52f88df9f..83fd6e9ac 100644 --- a/src/snapshot/metadata.rs +++ b/src/snapshot/metadata.rs @@ -133,6 +133,10 @@ impl InstanceContext { let rules = Arc::make_mut(&mut self.path_ignore_rules); rules.extend(new_rules); } + + pub fn set_script_type(&mut self, script_type: ScriptContextType) { + self.script_type = script_type + } } // serve_session always passes an option from the config file, but tests want it to be explict diff --git a/src/snapshot_middleware/project.rs b/src/snapshot_middleware/project.rs index 656409c0a..3d92bf6b8 100644 --- a/src/snapshot_middleware/project.rs +++ b/src/snapshot_middleware/project.rs @@ -30,6 +30,7 @@ pub fn snapshot_project( }); context.add_path_ignore_rules(rules); + context.set_script_type(project.script_type.unwrap_or_default()); match snapshot_project_node(&context, path, &project.name, &project.tree, vfs, None)? { Some(found_snapshot) => { From 0347382404bab63a407561ac8862af92934652c3 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Sat, 9 Sep 2023 16:34:10 +1000 Subject: [PATCH 15/22] tests: add build tests --- ..._end__tests__build__nested_runcontext.snap | 35 +++++++++++++++++++ .../nested_runcontext/default.project.json | 13 +++++++ .../nested_runcontext/folder1/test.server.lua | 0 .../folder2/default.project.json | 7 ++++ .../folder2/folder3/test.server.lua | 0 tests/tests/build.rs | 1 + 6 files changed, 56 insertions(+) create mode 100644 rojo-test/build-test-snapshots/end_to_end__tests__build__nested_runcontext.snap create mode 100644 rojo-test/build-tests/nested_runcontext/default.project.json create mode 100644 rojo-test/build-tests/nested_runcontext/folder1/test.server.lua create mode 100644 rojo-test/build-tests/nested_runcontext/folder2/default.project.json create mode 100644 rojo-test/build-tests/nested_runcontext/folder2/folder3/test.server.lua diff --git a/rojo-test/build-test-snapshots/end_to_end__tests__build__nested_runcontext.snap b/rojo-test/build-test-snapshots/end_to_end__tests__build__nested_runcontext.snap new file mode 100644 index 000000000..0ddc30519 --- /dev/null +++ b/rojo-test/build-test-snapshots/end_to_end__tests__build__nested_runcontext.snap @@ -0,0 +1,35 @@ +--- +source: tests/tests/build.rs +expression: contents +--- + + + + nested_runcontext + + + + folder1 + + + + test + 1 + + + + + + + folder2 + + + + test + 0 + + + + + + diff --git a/rojo-test/build-tests/nested_runcontext/default.project.json b/rojo-test/build-tests/nested_runcontext/default.project.json new file mode 100644 index 000000000..f05549029 --- /dev/null +++ b/rojo-test/build-tests/nested_runcontext/default.project.json @@ -0,0 +1,13 @@ +{ + "name": "nested_runcontext", + "scriptType": "RunContext", + "tree": { + "$className": "Folder", + "folder1": { + "$path": "folder1" + }, + "folder2": { + "$path": "folder2" + } + } +} diff --git a/rojo-test/build-tests/nested_runcontext/folder1/test.server.lua b/rojo-test/build-tests/nested_runcontext/folder1/test.server.lua new file mode 100644 index 000000000..e69de29bb diff --git a/rojo-test/build-tests/nested_runcontext/folder2/default.project.json b/rojo-test/build-tests/nested_runcontext/folder2/default.project.json new file mode 100644 index 000000000..9cd652fbf --- /dev/null +++ b/rojo-test/build-tests/nested_runcontext/folder2/default.project.json @@ -0,0 +1,7 @@ +{ + "name": "nested_runcontext", + "scriptType": "Class", + "tree": { + "$path": "folder3" + } +} diff --git a/rojo-test/build-tests/nested_runcontext/folder2/folder3/test.server.lua b/rojo-test/build-tests/nested_runcontext/folder2/folder3/test.server.lua new file mode 100644 index 000000000..e69de29bb diff --git a/tests/tests/build.rs b/tests/tests/build.rs index 4907449d2..01e87da73 100644 --- a/tests/tests/build.rs +++ b/tests/tests/build.rs @@ -44,6 +44,7 @@ gen_build_tests! { json_model_legacy_name, module_in_folder, module_init, + nested_runcontext, optional, project_composed_default, project_composed_file, From 35619f3254cebac4cae3fd5a565d5079d99a8356 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Sat, 9 Sep 2023 16:44:25 +1000 Subject: [PATCH 16/22] fix: changelog typo [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 142cfe3f7..5542c98d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,7 @@ * Added rich Source diffs in patch visualizer ([#748]) * Fix PatchTree performance issues ([#755]) * Don't override the initial enabled state for source diffing ([#760]) -* A `$scriptType` field has been added to the project.json schema, allowing for scripts to be differentiated as lasses or through RunContext ([#765]). +* A `$scriptType` field has been added to the project.json schema, allowing for scripts to be differentiated through classes or RunContext ([#765]). * Added support for `Terrain.MaterialColors` ([#770]) * Allow `Terrain` to be specified without a classname ([#771]) * Add Confirmation Behavior setting ([#774]) From 69f6be1d8961be73f68f38cb3be6d6aae3e8afd2 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Fri, 15 Sep 2023 07:41:56 +1000 Subject: [PATCH 17/22] refactor: change scriptType to be emitLegacyScripts --- CHANGELOG.md | 7 ++- .../nested_runcontext/default.project.json | 2 +- .../folder2/default.project.json | 2 +- src/project.rs | 11 +++- src/serve_session.rs | 2 +- src/snapshot/metadata.rs | 24 ++++---- ..._snapshot__tests__apply__add_property.snap | 3 +- ...s__apply__remove_property_after_patch.snap | 3 +- ...tests__apply__remove_property_initial.snap | 3 +- ...tests__apply__set_name_and_class_name.snap | 3 +- ...__snapshot__tests__compute__add_child.snap | 2 +- src/snapshot_middleware/lua.rs | 55 +++++++------------ src/snapshot_middleware/mod.rs | 2 +- src/snapshot_middleware/project.rs | 8 ++- ...t_middleware__csv__test__csv_from_vfs.snap | 2 +- ..._middleware__csv__test__csv_with_meta.snap | 2 +- ...t_middleware__dir__test__empty_folder.snap | 2 +- ...ddleware__dir__test__folder_in_folder.snap | 4 +- ...leware__json__test__instance_from_vfs.snap | 2 +- ...are__json_model__test__model_from_vfs.snap | 4 +- ...on_model__test__model_from_vfs_legacy.snap | 4 +- ...are__lua__test__class_client_from_vfs.snap | 2 +- ...are__lua__test__class_module_from_vfs.snap | 2 +- ...re__lua__test__class_module_with_meta.snap | 2 +- ...are__lua__test__class_script_disabled.snap | 2 +- ...re__lua__test__class_script_with_meta.snap | 2 +- ...are__lua__test__class_server_from_vfs.snap | 2 +- ...lua__test__runcontext_client_from_vfs.snap | 2 +- ...lua__test__runcontext_module_from_vfs.snap | 2 +- ...ua__test__runcontext_module_with_meta.snap | 2 +- ...lua__test__runcontext_script_disabled.snap | 2 +- ...ua__test__runcontext_script_with_meta.snap | 2 +- ...lua__test__runcontext_server_from_vfs.snap | 2 +- ...oject__test__project_from_direct_file.snap | 2 +- ...test__project_path_property_overrides.snap | 2 +- ..._project__test__project_with_children.snap | 4 +- ...t__test__project_with_path_to_project.snap | 2 +- ...ct_with_path_to_project_with_children.snap | 4 +- ...oject__test__project_with_path_to_txt.snap | 2 +- ...est__project_with_resolved_properties.snap | 2 +- ...t__project_with_unresolved_properties.snap | 2 +- ...leware__toml__test__instance_from_vfs.snap | 2 +- ...dleware__txt__test__instance_from_vfs.snap | 2 +- src/snapshot_middleware/util.rs | 5 ++ 44 files changed, 104 insertions(+), 96 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5542c98d3..b60b72e35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,10 +25,15 @@ * Added rich Source diffs in patch visualizer ([#748]) * Fix PatchTree performance issues ([#755]) * Don't override the initial enabled state for source diffing ([#760]) -* A `$scriptType` field has been added to the project.json schema, allowing for scripts to be differentiated through classes or RunContext ([#765]). * Added support for `Terrain.MaterialColors` ([#770]) * Allow `Terrain` to be specified without a classname ([#771]) * Add Confirmation Behavior setting ([#774]) +* Added the `emitLegacyScripts` field to the project format ([#765]). Right now, it defaults to `true`: + +| `$emitLegacyScripts` Value | Action Taken by Rojo | +|----------------------------|------------------------------------------------------------------------------------------------------------------| +| false | Rojo emits Scripts with the appropriate `RunContext` for `*.client.lua` and `*.server.lua` files in the project. | +| true (current default) | Rojo emits LocalScripts and Scripts with legacy Runcontext (same behavior as previously). | [#761]: https://github.com/rojo-rbx/rojo/pull/761 [#745]: https://github.com/rojo-rbx/rojo/pull/745 diff --git a/rojo-test/build-tests/nested_runcontext/default.project.json b/rojo-test/build-tests/nested_runcontext/default.project.json index f05549029..5327be9a8 100644 --- a/rojo-test/build-tests/nested_runcontext/default.project.json +++ b/rojo-test/build-tests/nested_runcontext/default.project.json @@ -1,6 +1,6 @@ { "name": "nested_runcontext", - "scriptType": "RunContext", + "emitLegacyScripts": false, "tree": { "$className": "Folder", "folder1": { diff --git a/rojo-test/build-tests/nested_runcontext/folder2/default.project.json b/rojo-test/build-tests/nested_runcontext/folder2/default.project.json index 9cd652fbf..67feff442 100644 --- a/rojo-test/build-tests/nested_runcontext/folder2/default.project.json +++ b/rojo-test/build-tests/nested_runcontext/folder2/default.project.json @@ -1,6 +1,6 @@ { "name": "nested_runcontext", - "scriptType": "Class", + "emitLegacyScripts": true, "tree": { "$path": "folder3" } diff --git a/src/project.rs b/src/project.rs index bcd123c14..15afa8448 100644 --- a/src/project.rs +++ b/src/project.rs @@ -8,7 +8,9 @@ use std::{ use serde::{Deserialize, Serialize}; use thiserror::Error; -use crate::{glob::Glob, resolution::UnresolvedValue, snapshot_middleware::ScriptContextType}; +use crate::{ + glob::Glob, resolution::UnresolvedValue, snapshot_middleware::emit_legacy_scripts_default, +}; static PROJECT_FILENAME: &str = "default.project.json"; @@ -76,8 +78,11 @@ pub struct Project { /// The mode to use when mapping scripts into Roblox. /// Can be either `Class` or `RunContext` and determines whether script /// behavior is set using the `RunContext` property or the script's `ClassName`. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub script_type: Option, + #[serde( + default = "emit_legacy_scripts_default", + skip_serializing_if = "Option::is_none" + )] + pub emit_legacy_scripts: Option, /// A list of globs, relative to the folder the project file is in, that /// match files that should be excluded if Rojo encounters them. diff --git a/src/serve_session.rs b/src/serve_session.rs index 4f0b7b6df..6f51f0a6f 100644 --- a/src/serve_session.rs +++ b/src/serve_session.rs @@ -123,7 +123,7 @@ impl ServeSession { let root_id = tree.get_root_id(); - let instance_context = InstanceContext::from(root_project.script_type); + let instance_context = InstanceContext::from(root_project.emit_legacy_scripts); log::trace!("Generating snapshot of instances from VFS"); let snapshot = snapshot_from_vfs(&instance_context, &vfs, start_path)?; diff --git a/src/snapshot/metadata.rs b/src/snapshot/metadata.rs index 83fd6e9ac..295735ef6 100644 --- a/src/snapshot/metadata.rs +++ b/src/snapshot/metadata.rs @@ -7,7 +7,8 @@ use std::{ use serde::{Deserialize, Serialize}; use crate::{ - glob::Glob, path_serializer, project::ProjectNode, snapshot_middleware::ScriptContextType, + glob::Glob, path_serializer, project::ProjectNode, + snapshot_middleware::emit_legacy_scripts_default, }; /// Rojo-specific metadata that can be associated with an instance or a snapshot @@ -105,14 +106,14 @@ impl Default for InstanceMetadata { pub struct InstanceContext { #[serde(skip_serializing_if = "Vec::is_empty")] pub path_ignore_rules: Arc>, - pub script_type: ScriptContextType, + pub emit_legacy_scripts: bool, } impl InstanceContext { pub fn new() -> Self { Self { path_ignore_rules: Arc::new(Vec::new()), - script_type: ScriptContextType::Class, + emit_legacy_scripts: emit_legacy_scripts_default().unwrap(), } } @@ -134,26 +135,27 @@ impl InstanceContext { rules.extend(new_rules); } - pub fn set_script_type(&mut self, script_type: ScriptContextType) { - self.script_type = script_type + pub fn set_emit_legacy_scripts(&mut self, emit_legacy_scripts: bool) { + self.emit_legacy_scripts = emit_legacy_scripts } } // serve_session always passes an option from the config file, but tests want it to be explict #[cfg(test)] -impl From for InstanceContext { - fn from(script_type: ScriptContextType) -> Self { +impl From for InstanceContext { + fn from(emit_legacy_scripts: bool) -> Self { Self { - script_type, + emit_legacy_scripts, ..Self::new() } } } -impl From> for InstanceContext { - fn from(script_type: Option) -> Self { +impl From> for InstanceContext { + fn from(emit_legacy_scripts: Option) -> Self { Self { - script_type: script_type.unwrap_or_default(), + emit_legacy_scripts: emit_legacy_scripts + .unwrap_or_else(|| emit_legacy_scripts_default().unwrap()), ..Self::new() } } diff --git a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__add_property.snap b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__add_property.snap index 288705b7b..0d594dbc0 100644 --- a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__add_property.snap +++ b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__add_property.snap @@ -1,7 +1,6 @@ --- source: src/snapshot/tests/apply.rs expression: tree_view - --- id: id-1 name: ROOT @@ -13,6 +12,6 @@ metadata: ignore_unknown_instances: false relevant_paths: [] context: - script_type: Class + emit_legacy_scripts: true children: [] diff --git a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_after_patch.snap b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_after_patch.snap index 6fe548bc3..b6fcbbd08 100644 --- a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_after_patch.snap +++ b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_after_patch.snap @@ -10,5 +10,6 @@ metadata: ignore_unknown_instances: false relevant_paths: [] context: - script_type: Class + emit_legacy_scripts: true children: [] + diff --git a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_initial.snap b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_initial.snap index 4e6989cee..84b3c3d1e 100644 --- a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_initial.snap +++ b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__remove_property_initial.snap @@ -1,7 +1,6 @@ --- source: src/snapshot/tests/apply.rs expression: tree_view - --- id: id-1 name: ROOT @@ -13,6 +12,6 @@ metadata: ignore_unknown_instances: false relevant_paths: [] context: - script_type: Class + emit_legacy_scripts: true children: [] diff --git a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__set_name_and_class_name.snap b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__set_name_and_class_name.snap index d2c96c9da..325c86f3c 100644 --- a/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__set_name_and_class_name.snap +++ b/src/snapshot/tests/snapshots/librojo__snapshot__tests__apply__set_name_and_class_name.snap @@ -10,5 +10,6 @@ metadata: ignore_unknown_instances: false relevant_paths: [] context: - script_type: Class + emit_legacy_scripts: true children: [] + diff --git a/src/snapshot/tests/snapshots/librojo__snapshot__tests__compute__add_child.snap b/src/snapshot/tests/snapshots/librojo__snapshot__tests__compute__add_child.snap index 82389218d..94ddf12fb 100644 --- a/src/snapshot/tests/snapshots/librojo__snapshot__tests__compute__add_child.snap +++ b/src/snapshot/tests/snapshots/librojo__snapshot__tests__compute__add_child.snap @@ -11,7 +11,7 @@ added_instances: ignore_unknown_instances: false relevant_paths: [] context: - script_type: Class + emit_legacy_scripts: true name: New class_name: Folder properties: {} diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index dbe67d89e..c99b4837e 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -3,7 +3,6 @@ use std::{collections::HashMap, path::Path, str}; use anyhow::Context; use memofs::{IoResultExt, Vfs}; use rbx_dom_weak::types::Enum; -use serde::{Deserialize, Serialize}; use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot}; @@ -13,13 +12,6 @@ use super::{ util::match_trailing, }; -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Default)] -pub enum ScriptContextType { - #[default] - Class, - RunContext, -} - #[derive(Debug)] enum ScriptType { Server, @@ -58,13 +50,11 @@ pub fn snapshot_lua( return Ok(None); }; - let is_run_context_enabled = context.script_type == ScriptContextType::RunContext; - - let (class_name, run_context) = match (is_run_context_enabled, script_type) { - (true, ScriptType::Server) => ("Script", run_context_enums.get("Server")), - (true, ScriptType::Client) => ("Script", run_context_enums.get("Client")), - (false, ScriptType::Server) => ("Script", run_context_enums.get("Legacy")), - (false, ScriptType::Client) => ("LocalScript", None), + let (class_name, run_context) = match (context.emit_legacy_scripts, script_type) { + (false, ScriptType::Server) => ("Script", run_context_enums.get("Server")), + (false, ScriptType::Client) => ("Script", run_context_enums.get("Client")), + (true, ScriptType::Server) => ("Script", run_context_enums.get("Legacy")), + (true, ScriptType::Client) => ("LocalScript", None), (_, ScriptType::Module) => ("ModuleScript", None), }; @@ -158,7 +148,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::Class), + &InstanceContext::from(true), &mut vfs, Path::new("/foo.lua"), ) @@ -179,7 +169,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::RunContext), + &InstanceContext::from(false), &mut vfs, Path::new("/foo.lua"), ) @@ -200,7 +190,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::Class), + &InstanceContext::from(true), &mut vfs, Path::new("/foo.server.lua"), ) @@ -221,7 +211,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::RunContext), + &InstanceContext::from(false), &mut vfs, Path::new("/foo.server.lua"), ) @@ -242,7 +232,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::Class), + &InstanceContext::from(true), &mut vfs, Path::new("/foo.client.lua"), ) @@ -263,7 +253,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::RunContext), + &InstanceContext::from(false), &mut vfs, Path::new("/foo.client.lua"), ) @@ -289,13 +279,10 @@ mod test { let mut vfs = Vfs::new(imfs); - let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::Class), - &mut vfs, - Path::new("/root"), - ) - .unwrap() - .unwrap(); + let instance_snapshot = + snapshot_lua(&InstanceContext::from(true), &mut vfs, Path::new("/root")) + .unwrap() + .unwrap(); insta::with_settings!({ sort_maps => true }, { insta::assert_yaml_snapshot!(instance_snapshot); @@ -322,7 +309,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::Class), + &InstanceContext::from(true), &mut vfs, Path::new("/foo.lua"), ) @@ -354,7 +341,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::RunContext), + &InstanceContext::from(false), &mut vfs, Path::new("/foo.lua"), ) @@ -386,7 +373,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::Class), + &InstanceContext::from(true), &mut vfs, Path::new("/foo.server.lua"), ) @@ -418,7 +405,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::RunContext), + &InstanceContext::from(false), &mut vfs, Path::new("/foo.server.lua"), ) @@ -452,7 +439,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::Class), + &InstanceContext::from(true), &mut vfs, Path::new("/bar.server.lua"), ) @@ -486,7 +473,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(ScriptContextType::RunContext), + &InstanceContext::from(false), &mut vfs, Path::new("/bar.server.lua"), ) diff --git a/src/snapshot_middleware/mod.rs b/src/snapshot_middleware/mod.rs index cb079cc6c..d8cd39409 100644 --- a/src/snapshot_middleware/mod.rs +++ b/src/snapshot_middleware/mod.rs @@ -38,7 +38,7 @@ use self::{ util::PathExt, }; -pub use self::{lua::ScriptContextType, project::snapshot_project_node}; +pub use self::{project::snapshot_project_node, util::emit_legacy_scripts_default}; /// The main entrypoint to the snapshot function. This function can be pointed /// at any path and will return something if Rojo knows how to deal with it. diff --git a/src/snapshot_middleware/project.rs b/src/snapshot_middleware/project.rs index 3d92bf6b8..9df50c9b2 100644 --- a/src/snapshot_middleware/project.rs +++ b/src/snapshot_middleware/project.rs @@ -12,7 +12,7 @@ use crate::{ }, }; -use super::snapshot_from_vfs; +use super::{emit_legacy_scripts_default, snapshot_from_vfs}; pub fn snapshot_project( context: &InstanceContext, @@ -30,7 +30,11 @@ pub fn snapshot_project( }); context.add_path_ignore_rules(rules); - context.set_script_type(project.script_type.unwrap_or_default()); + context.set_emit_legacy_scripts( + project + .emit_legacy_scripts + .unwrap_or_else(|| emit_legacy_scripts_default().unwrap()), + ); match snapshot_project_node(&context, path, &project.name, &project.tree, vfs, None)? { Some(found_snapshot) => { diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_from_vfs.snap index 379d7881b..50ce53c11 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_from_vfs.snap @@ -11,7 +11,7 @@ metadata: - /foo.csv - /foo.meta.json context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: LocalizationTable properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_with_meta.snap index bceaf9a43..c91924f8c 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_with_meta.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__csv__test__csv_with_meta.snap @@ -11,7 +11,7 @@ metadata: - /foo.csv - /foo.meta.json context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: LocalizationTable properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__empty_folder.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__empty_folder.snap index f2469410d..4c0dcbbf4 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__empty_folder.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__empty_folder.snap @@ -18,7 +18,7 @@ metadata: - /foo/init.client.luau - /foo/init.csv context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: Folder properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__folder_in_folder.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__folder_in_folder.snap index a596ebe81..6238fe68f 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__folder_in_folder.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__dir__test__folder_in_folder.snap @@ -18,7 +18,7 @@ metadata: - /foo/init.client.luau - /foo/init.csv context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: Folder properties: {} @@ -39,7 +39,7 @@ children: - /foo/Child/init.client.luau - /foo/Child/init.csv context: - script_type: Class + emit_legacy_scripts: true name: Child class_name: Folder properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json__test__instance_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json__test__instance_from_vfs.snap index 0cd2265f4..9cc320ebb 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json__test__instance_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json__test__instance_from_vfs.snap @@ -11,7 +11,7 @@ metadata: - /foo.json - /foo.meta.json context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs.snap index 754acf3f3..e3ee581e0 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs.snap @@ -10,7 +10,7 @@ metadata: relevant_paths: - /foo.model.json context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: IntValue properties: @@ -22,7 +22,7 @@ children: ignore_unknown_instances: false relevant_paths: [] context: - script_type: Class + emit_legacy_scripts: true name: The Child class_name: StringValue properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs_legacy.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs_legacy.snap index 754acf3f3..e3ee581e0 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs_legacy.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__json_model__test__model_from_vfs_legacy.snap @@ -10,7 +10,7 @@ metadata: relevant_paths: - /foo.model.json context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: IntValue properties: @@ -22,7 +22,7 @@ children: ignore_unknown_instances: false relevant_paths: [] context: - script_type: Class + emit_legacy_scripts: true name: The Child class_name: StringValue properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_client_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_client_from_vfs.snap index 763c638c6..5f5f6e9a1 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_client_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_client_from_vfs.snap @@ -11,7 +11,7 @@ metadata: - /foo.client.lua - /foo.meta.json context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: LocalScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_module_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_module_from_vfs.snap index e59bcda3c..de2471b9a 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_module_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_module_from_vfs.snap @@ -11,7 +11,7 @@ metadata: - /foo.lua - /foo.meta.json context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_module_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_module_with_meta.snap index e244cf2b2..32d70c708 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_module_with_meta.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_module_with_meta.snap @@ -11,7 +11,7 @@ metadata: - /foo.lua - /foo.meta.json context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_script_disabled.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_script_disabled.snap index 0717f0960..2c5546a53 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_script_disabled.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_script_disabled.snap @@ -11,7 +11,7 @@ metadata: - /bar.server.lua - /bar.meta.json context: - script_type: Class + emit_legacy_scripts: true name: bar class_name: Script properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_script_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_script_with_meta.snap index 14ba97be1..e4e31ff96 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_script_with_meta.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_script_with_meta.snap @@ -11,7 +11,7 @@ metadata: - /foo.server.lua - /foo.meta.json context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: Script properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_server_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_server_from_vfs.snap index 77e1eac47..b70b9cc2b 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_server_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__class_server_from_vfs.snap @@ -11,7 +11,7 @@ metadata: - /foo.server.lua - /foo.meta.json context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: Script properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_client_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_client_from_vfs.snap index e1873aa8f..6ad72d084 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_client_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_client_from_vfs.snap @@ -11,7 +11,7 @@ metadata: - /foo.client.lua - /foo.meta.json context: - script_type: RunContext + emit_legacy_scripts: false name: foo class_name: Script properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_from_vfs.snap index 1c8fb22bc..83be811be 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_from_vfs.snap @@ -11,7 +11,7 @@ metadata: - /foo.lua - /foo.meta.json context: - script_type: RunContext + emit_legacy_scripts: false name: foo class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_with_meta.snap index e5b7e36d7..98a88ec7f 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_with_meta.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_module_with_meta.snap @@ -11,7 +11,7 @@ metadata: - /foo.lua - /foo.meta.json context: - script_type: RunContext + emit_legacy_scripts: false name: foo class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_disabled.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_disabled.snap index 38f8ab7b4..c47b83dc3 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_disabled.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_disabled.snap @@ -11,7 +11,7 @@ metadata: - /bar.server.lua - /bar.meta.json context: - script_type: RunContext + emit_legacy_scripts: false name: bar class_name: Script properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_with_meta.snap index 0e0f27520..72d24206f 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_with_meta.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_script_with_meta.snap @@ -11,7 +11,7 @@ metadata: - /foo.server.lua - /foo.meta.json context: - script_type: RunContext + emit_legacy_scripts: false name: foo class_name: Script properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_server_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_server_from_vfs.snap index 9bdf4e055..2b902f964 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_server_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__runcontext_server_from_vfs.snap @@ -11,7 +11,7 @@ metadata: - /foo.server.lua - /foo.meta.json context: - script_type: RunContext + emit_legacy_scripts: false name: foo class_name: Script properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_from_direct_file.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_from_direct_file.snap index a2bc5ec8a..bd5db23db 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_from_direct_file.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_from_direct_file.snap @@ -10,7 +10,7 @@ metadata: relevant_paths: - /foo/hello.project.json context: - script_type: Class + emit_legacy_scripts: true name: direct-project class_name: Model properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_path_property_overrides.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_path_property_overrides.snap index f5df1efe1..77cb44c96 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_path_property_overrides.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_path_property_overrides.snap @@ -11,7 +11,7 @@ metadata: - /foo/other.project.json - /foo/default.project.json context: - script_type: Class + emit_legacy_scripts: true name: path-property-override class_name: StringValue properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_children.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_children.snap index da1431671..914a2f95e 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_children.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_children.snap @@ -10,7 +10,7 @@ metadata: relevant_paths: - /foo.project.json context: - script_type: Class + emit_legacy_scripts: true name: children class_name: Folder properties: {} @@ -26,7 +26,7 @@ children: - Folder relevant_paths: [] context: - script_type: Class + emit_legacy_scripts: true name: Child class_name: Model properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project.snap index bb2a10d09..02e6ee0ba 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project.snap @@ -11,7 +11,7 @@ metadata: - /foo/other.project.json - /foo/default.project.json context: - script_type: Class + emit_legacy_scripts: true name: path-project class_name: Model properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project_with_children.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project_with_children.snap index a5f6dcb26..baf643653 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project_with_children.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_project_with_children.snap @@ -11,7 +11,7 @@ metadata: - /foo/other.project.json - /foo/default.project.json context: - script_type: Class + emit_legacy_scripts: true name: path-child-project class_name: Folder properties: {} @@ -27,7 +27,7 @@ children: - Folder relevant_paths: [] context: - script_type: Class + emit_legacy_scripts: true name: SomeChild class_name: Model properties: {} diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_txt.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_txt.snap index b0fb9b09a..223c366cd 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_txt.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_path_to_txt.snap @@ -12,7 +12,7 @@ metadata: - /foo/other.meta.json - /foo/default.project.json context: - script_type: Class + emit_legacy_scripts: true name: path-project class_name: StringValue properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_resolved_properties.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_resolved_properties.snap index b03dbc514..eddb4e040 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_resolved_properties.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_resolved_properties.snap @@ -10,7 +10,7 @@ metadata: relevant_paths: - /foo.project.json context: - script_type: Class + emit_legacy_scripts: true name: resolved-properties class_name: StringValue properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_unresolved_properties.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_unresolved_properties.snap index 7a8f3b225..8bd6e28b8 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_unresolved_properties.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__project__test__project_with_unresolved_properties.snap @@ -10,7 +10,7 @@ metadata: relevant_paths: - /foo.project.json context: - script_type: Class + emit_legacy_scripts: true name: unresolved-properties class_name: StringValue properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__toml__test__instance_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__toml__test__instance_from_vfs.snap index 32f9b8a9b..329bdbcd3 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__toml__test__instance_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__toml__test__instance_from_vfs.snap @@ -11,7 +11,7 @@ metadata: - /foo.toml - /foo.meta.json context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__txt__test__instance_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__txt__test__instance_from_vfs.snap index 0c5b88b5d..aa3e0f067 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__txt__test__instance_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__txt__test__instance_from_vfs.snap @@ -11,7 +11,7 @@ metadata: - /foo.txt - /foo.meta.json context: - script_type: Class + emit_legacy_scripts: true name: foo class_name: StringValue properties: diff --git a/src/snapshot_middleware/util.rs b/src/snapshot_middleware/util.rs index 16648eae9..625910b77 100644 --- a/src/snapshot_middleware/util.rs +++ b/src/snapshot_middleware/util.rs @@ -41,3 +41,8 @@ where .with_context(|| format!("Path did not end in {}: {}", suffix, 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 { + Some(true) +} From 3b71f631e7a189213fb1f77a55dcb5d498e3ae53 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Fri, 15 Sep 2023 07:44:51 +1000 Subject: [PATCH 18/22] fix(changelog): clarity [skip ci] --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b60b72e35..35bb1a50a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,12 +28,12 @@ * Added support for `Terrain.MaterialColors` ([#770]) * Allow `Terrain` to be specified without a classname ([#771]) * Add Confirmation Behavior setting ([#774]) -* Added the `emitLegacyScripts` field to the project format ([#765]). Right now, it defaults to `true`: +* Added the `emitLegacyScripts` field to the project format ([#765]). The behavior is outlined below: -| `$emitLegacyScripts` Value | Action Taken by Rojo | +| `emitLegacyScripts` Value | Action Taken by Rojo | |----------------------------|------------------------------------------------------------------------------------------------------------------| | false | Rojo emits Scripts with the appropriate `RunContext` for `*.client.lua` and `*.server.lua` files in the project. | -| true (current default) | Rojo emits LocalScripts and Scripts with legacy Runcontext (same behavior as previously). | +| true (default) | Rojo emits LocalScripts and Scripts with legacy Runcontext (same behavior as previously). | [#761]: https://github.com/rojo-rbx/rojo/pull/761 [#745]: https://github.com/rojo-rbx/rojo/pull/745 From 8cb9a7ba581273c28e3ce9d9ec0be56d9c11eb33 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Sat, 16 Sep 2023 06:38:29 +1000 Subject: [PATCH 19/22] refactor(InstanceContext): switch to constructor methods --- src/serve_session.rs | 3 ++- src/snapshot/metadata.rs | 31 +++++++++--------------------- src/snapshot_middleware/lua.rs | 35 ++++++++++++++++++---------------- 3 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/serve_session.rs b/src/serve_session.rs index 6f51f0a6f..85ae77934 100644 --- a/src/serve_session.rs +++ b/src/serve_session.rs @@ -123,7 +123,8 @@ impl ServeSession { let root_id = tree.get_root_id(); - let instance_context = InstanceContext::from(root_project.emit_legacy_scripts); + let instance_context = + InstanceContext::with_emit_legacy_scripts(root_project.emit_legacy_scripts); log::trace!("Generating snapshot of instances from VFS"); let snapshot = snapshot_from_vfs(&instance_context, &vfs, start_path)?; diff --git a/src/snapshot/metadata.rs b/src/snapshot/metadata.rs index 295735ef6..54675c087 100644 --- a/src/snapshot/metadata.rs +++ b/src/snapshot/metadata.rs @@ -117,6 +117,14 @@ impl InstanceContext { } } + pub fn with_emit_legacy_scripts(emit_legacy_scripts: Option) -> Self { + Self { + emit_legacy_scripts: emit_legacy_scripts + .unwrap_or_else(|| emit_legacy_scripts_default().unwrap()), + ..Self::new() + } + } + /// Extend the list of ignore rules in the context with the given new rules. pub fn add_path_ignore_rules(&mut self, new_rules: I) where @@ -136,28 +144,7 @@ impl InstanceContext { } pub fn set_emit_legacy_scripts(&mut self, emit_legacy_scripts: bool) { - self.emit_legacy_scripts = emit_legacy_scripts - } -} - -// serve_session always passes an option from the config file, but tests want it to be explict -#[cfg(test)] -impl From for InstanceContext { - fn from(emit_legacy_scripts: bool) -> Self { - Self { - emit_legacy_scripts, - ..Self::new() - } - } -} - -impl From> for InstanceContext { - fn from(emit_legacy_scripts: Option) -> Self { - Self { - emit_legacy_scripts: emit_legacy_scripts - .unwrap_or_else(|| emit_legacy_scripts_default().unwrap()), - ..Self::new() - } + self.emit_legacy_scripts = emit_legacy_scripts; } } diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index c99b4837e..1307b0666 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -148,7 +148,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(true), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &mut vfs, Path::new("/foo.lua"), ) @@ -169,7 +169,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(false), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/foo.lua"), ) @@ -190,7 +190,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(true), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &mut vfs, Path::new("/foo.server.lua"), ) @@ -211,7 +211,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(false), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/foo.server.lua"), ) @@ -232,7 +232,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(true), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &mut vfs, Path::new("/foo.client.lua"), ) @@ -253,7 +253,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(false), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/foo.client.lua"), ) @@ -279,10 +279,13 @@ mod test { let mut vfs = Vfs::new(imfs); - let instance_snapshot = - snapshot_lua(&InstanceContext::from(true), &mut vfs, Path::new("/root")) - .unwrap() - .unwrap(); + let instance_snapshot = snapshot_lua( + &InstanceContext::with_emit_legacy_scripts(Some(true)), + &mut vfs, + Path::new("/root"), + ) + .unwrap() + .unwrap(); insta::with_settings!({ sort_maps => true }, { insta::assert_yaml_snapshot!(instance_snapshot); @@ -309,7 +312,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(true), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &mut vfs, Path::new("/foo.lua"), ) @@ -341,7 +344,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(false), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/foo.lua"), ) @@ -373,7 +376,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(true), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &mut vfs, Path::new("/foo.server.lua"), ) @@ -405,7 +408,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(false), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/foo.server.lua"), ) @@ -439,7 +442,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(true), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &mut vfs, Path::new("/bar.server.lua"), ) @@ -473,7 +476,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(false), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/bar.server.lua"), ) From c42a00a85b1e6e0b47249dfde234291522a154ad Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Sat, 16 Sep 2023 06:42:20 +1000 Subject: [PATCH 20/22] chore: update doc comments [skip ci] --- src/project.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/project.rs b/src/project.rs index 15afa8448..1a645b76a 100644 --- a/src/project.rs +++ b/src/project.rs @@ -75,9 +75,8 @@ pub struct Project { #[serde(skip_serializing_if = "Option::is_none")] pub serve_address: Option, - /// The mode to use when mapping scripts into Roblox. - /// Can be either `Class` or `RunContext` and determines whether script - /// behavior is set using the `RunContext` property or the script's `ClassName`. + /// Determines if rojo should emit scripts with the appropriate `RunContext` for `*.client.lua` and `*.server.lua` files in the project. + /// Or, if rojo should keep the legacy behavior of emitting LocalScripts and Scripts with legacy Runcontext #[serde( default = "emit_legacy_scripts_default", skip_serializing_if = "Option::is_none" From 92f8bc6d8fa1fe77cc6582773e662e87b276985a Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Sat, 16 Sep 2023 09:22:50 +1000 Subject: [PATCH 21/22] chore: review comments --- src/snapshot/metadata.rs | 3 ++- src/snapshot_middleware/project.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/snapshot/metadata.rs b/src/snapshot/metadata.rs index 54675c087..1a3273ed7 100644 --- a/src/snapshot/metadata.rs +++ b/src/snapshot/metadata.rs @@ -120,7 +120,8 @@ impl InstanceContext { pub fn with_emit_legacy_scripts(emit_legacy_scripts: Option) -> Self { Self { emit_legacy_scripts: emit_legacy_scripts - .unwrap_or_else(|| emit_legacy_scripts_default().unwrap()), + .or_else(emit_legacy_scripts_default) + .unwrap(), ..Self::new() } } diff --git a/src/snapshot_middleware/project.rs b/src/snapshot_middleware/project.rs index 9df50c9b2..d1b4a2e48 100644 --- a/src/snapshot_middleware/project.rs +++ b/src/snapshot_middleware/project.rs @@ -33,7 +33,8 @@ pub fn snapshot_project( context.set_emit_legacy_scripts( project .emit_legacy_scripts - .unwrap_or_else(|| emit_legacy_scripts_default().unwrap()), + .or_else(emit_legacy_scripts_default) + .unwrap(), ); match snapshot_project_node(&context, path, &project.name, &project.tree, vfs, None)? { From 7b32020b62160fcb81f0bc32df8f0161a3febf66 Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Fri, 22 Sep 2023 11:24:04 +1000 Subject: [PATCH 22/22] Update CHANGELOG.md [skip ci] Co-authored-by: Micah --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35bb1a50a..f6e171f13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,10 +30,10 @@ * Add Confirmation Behavior setting ([#774]) * Added the `emitLegacyScripts` field to the project format ([#765]). The behavior is outlined below: -| `emitLegacyScripts` Value | Action Taken by Rojo | -|----------------------------|------------------------------------------------------------------------------------------------------------------| -| false | Rojo emits Scripts with the appropriate `RunContext` for `*.client.lua` and `*.server.lua` files in the project. | -| true (default) | Rojo emits LocalScripts and Scripts with legacy Runcontext (same behavior as previously). | +| `emitLegacyScripts` Value | Action Taken by Rojo | +|----------------------------|--------------------------------------------------------------------------------------------------------------------| +| false | Rojo emits Scripts with the appropriate `RunContext` for `*.client.lua` and `*.server.lua` files in the project. | +| true (default) | Rojo emits LocalScripts and Scripts with legacy `RunContext` (same behavior as previously). | [#761]: https://github.com/rojo-rbx/rojo/pull/761 [#745]: https://github.com/rojo-rbx/rojo/pull/745