diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f26d92e3..f6e171f13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +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]). 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). | [#761]: https://github.com/rojo-rbx/rojo/pull/761 [#745]: https://github.com/rojo-rbx/rojo/pull/745 @@ -53,6 +59,7 @@ [#748]: https://github.com/rojo-rbx/rojo/pull/748 [#755]: https://github.com/rojo-rbx/rojo/pull/755 [#760]: https://github.com/rojo-rbx/rojo/pull/760 +[#765]: https://github.com/rojo-rbx/rojo/pull/765 [#770]: https://github.com/rojo-rbx/rojo/pull/770 [#771]: https://github.com/rojo-rbx/rojo/pull/771 [#774]: https://github.com/rojo-rbx/rojo/pull/774 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-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/build-tests/nested_runcontext/default.project.json b/rojo-test/build-tests/nested_runcontext/default.project.json new file mode 100644 index 000000000..5327be9a8 --- /dev/null +++ b/rojo-test/build-tests/nested_runcontext/default.project.json @@ -0,0 +1,13 @@ +{ + "name": "nested_runcontext", + "emitLegacyScripts": false, + "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..67feff442 --- /dev/null +++ b/rojo-test/build-tests/nested_runcontext/folder2/default.project.json @@ -0,0 +1,7 @@ +{ + "name": "nested_runcontext", + "emitLegacyScripts": true, + "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/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/src/project.rs b/src/project.rs index e70005d06..1a645b76a 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}; +use crate::{ + glob::Glob, resolution::UnresolvedValue, snapshot_middleware::emit_legacy_scripts_default, +}; static PROJECT_FILENAME: &str = "default.project.json"; @@ -73,6 +75,14 @@ pub struct Project { #[serde(skip_serializing_if = "Option::is_none")] pub serve_address: Option, + /// 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" + )] + 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. #[serde(default, skip_serializing_if = "Vec::is_empty")] diff --git a/src/serve_session.rs b/src/serve_session.rs index 9dab5446e..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::default(); + 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 192a00013..1a3273ed7 100644 --- a/src/snapshot/metadata.rs +++ b/src/snapshot/metadata.rs @@ -6,7 +6,10 @@ use std::{ use serde::{Deserialize, Serialize}; -use crate::{glob::Glob, path_serializer, project::ProjectNode}; +use crate::{ + 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 /// of an instance. @@ -103,9 +106,26 @@ impl Default for InstanceMetadata { pub struct InstanceContext { #[serde(skip_serializing_if = "Vec::is_empty")] pub path_ignore_rules: Arc>, + pub emit_legacy_scripts: bool, } impl InstanceContext { + pub fn new() -> Self { + Self { + path_ignore_rules: Arc::new(Vec::new()), + emit_legacy_scripts: emit_legacy_scripts_default().unwrap(), + } + } + + pub fn with_emit_legacy_scripts(emit_legacy_scripts: Option) -> Self { + Self { + emit_legacy_scripts: emit_legacy_scripts + .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 @@ -123,13 +143,15 @@ impl InstanceContext { let rules = Arc::make_mut(&mut self.path_ignore_rules); rules.extend(new_rules); } + + pub fn set_emit_legacy_scripts(&mut self, emit_legacy_scripts: bool) { + self.emit_legacy_scripts = emit_legacy_scripts; + } } impl Default for InstanceContext { fn default() -> Self { - InstanceContext { - path_ignore_rules: Arc::new(Vec::new()), - } + 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 9d5e9d778..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 @@ -12,6 +11,7 @@ properties: metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + 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 f8706912d..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 @@ -9,5 +9,7 @@ properties: {} metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + 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 936658f1d..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 @@ -12,6 +11,7 @@ properties: metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + 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 634b4d641..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 @@ -9,5 +9,7 @@ properties: {} metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + 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 c4695b7c5..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 @@ -10,7 +10,8 @@ added_instances: metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + 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 ba2216263..1307b0666 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -1,8 +1,8 @@ -use std::{path::Path, str}; +use std::{collections::HashMap, path::Path, str}; use anyhow::Context; -use maplit::hashmap; use memofs::{IoResultExt, Vfs}; +use rbx_dom_weak::types::Enum; use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot}; @@ -12,6 +12,13 @@ use super::{ util::match_trailing, }; +#[derive(Debug)] +enum ScriptType { + Server, + Client, + Module, +} + /// Core routine for turning Lua files into snapshots. pub fn snapshot_lua( context: &InstanceContext, @@ -20,36 +27,58 @@ 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 run_context_enums = &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") { - ("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 (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), + }; + 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::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(), + ); + } + 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) @@ -107,26 +136,53 @@ pub fn snapshot_lua_init( mod test { use super::*; + use maplit::hashmap; 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(); + + let mut vfs = Vfs::new(imfs); + + let instance_snapshot = snapshot_lua( + &InstanceContext::with_emit_legacy_scripts(Some(true)), + &mut vfs, + Path::new("/foo.lua"), + ) + .unwrap() + .unwrap(); + + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); + } + + #[test] + 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::default(), &mut vfs, Path::new("/foo.lua")) - .unwrap() - .unwrap(); + let instance_snapshot = snapshot_lua( + &InstanceContext::with_emit_legacy_scripts(Some(false)), + &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] - fn server_from_vfs() { + fn class_server_from_vfs() { let mut imfs = InMemoryFs::new(); imfs.load_snapshot("/foo.server.lua", VfsSnapshot::file("Hello there!")) .unwrap(); @@ -134,18 +190,41 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::default(), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &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] - 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::with_emit_legacy_scripts(Some(false)), + &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(); @@ -153,14 +232,37 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::default(), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &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); + }); + } + + #[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::with_emit_legacy_scripts(Some(false)), + &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"] @@ -177,16 +279,21 @@ mod test { let mut vfs = Vfs::new(imfs); - let instance_snapshot = - snapshot_lua(&InstanceContext::default(), &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::assert_yaml_snapshot!(instance_snapshot); + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); } #[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(); @@ -204,16 +311,85 @@ mod test { let mut vfs = Vfs::new(imfs); - let instance_snapshot = - snapshot_lua(&InstanceContext::default(), &mut vfs, Path::new("/foo.lua")) - .unwrap() - .unwrap(); + let instance_snapshot = snapshot_lua( + &InstanceContext::with_emit_legacy_scripts(Some(true)), + &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] - 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::with_emit_legacy_scripts(Some(false)), + &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(); + imfs.load_snapshot( + "/foo.meta.json", + VfsSnapshot::file( + r#" + { + "ignoreUnknownInstances": true + } + "#, + ), + ) + .unwrap(); + + let mut vfs = Vfs::new(imfs); + + let instance_snapshot = snapshot_lua( + &InstanceContext::with_emit_legacy_scripts(Some(true)), + &mut vfs, + Path::new("/foo.server.lua"), + ) + .unwrap() + .unwrap(); + + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); + } + + #[test] + fn runcontext_script_with_meta() { let mut imfs = InMemoryFs::new(); imfs.load_snapshot("/foo.server.lua", VfsSnapshot::file("Hello there!")) .unwrap(); @@ -232,18 +408,54 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::default(), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &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] + fn class_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::with_emit_legacy_scripts(Some(true)), + &mut vfs, + Path::new("/bar.server.lua"), + ) + .unwrap() + .unwrap(); + + insta::with_settings!({ sort_maps => true }, { + insta::assert_yaml_snapshot!(instance_snapshot); + }); } #[test] - fn script_disabled() { + fn runcontext_script_disabled() { let mut imfs = InMemoryFs::new(); imfs.load_snapshot("/bar.server.lua", VfsSnapshot::file("Hello there!")) .unwrap(); @@ -264,7 +476,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::default(), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/bar.server.lua"), ) diff --git a/src/snapshot_middleware/mod.rs b/src/snapshot_middleware/mod.rs index c690a2239..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::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 a451abc9b..d1b4a2e48 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,6 +30,12 @@ pub fn snapshot_project( }); context.add_path_ignore_rules(rules); + context.set_emit_legacy_scripts( + project + .emit_legacy_scripts + .or_else(emit_legacy_scripts_default) + .unwrap(), + ); match snapshot_project_node(&context, path, &project.name, &project.tree, vfs, None)? { Some(found_snapshot) => { @@ -77,7 +83,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::new().context(context); if let Some(path_node) = &node.path { let path = path_node.path(); 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..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 @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.csv - /foo.meta.json - context: {} + context: + 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 eda826061..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 @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.csv - /foo.meta.json - context: {} + context: + 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 e59da8db6..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 @@ -17,7 +17,8 @@ metadata: - /foo/init.client.lua - /foo/init.client.luau - /foo/init.csv - context: {} + context: + 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 8c2ee9cc7..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 @@ -17,7 +17,8 @@ metadata: - /foo/init.client.lua - /foo/init.client.luau - /foo/init.csv - context: {} + context: + emit_legacy_scripts: true 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: + 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 b1cca7cb9..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 @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.json - /foo.meta.json - context: {} + context: + 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 5d4db1fcc..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 @@ -9,7 +9,8 @@ metadata: Path: /foo.model.json relevant_paths: - /foo.model.json - context: {} + context: + emit_legacy_scripts: true name: foo class_name: IntValue properties: @@ -20,7 +21,8 @@ children: metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + 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 5d4db1fcc..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 @@ -9,7 +9,8 @@ metadata: Path: /foo.model.json relevant_paths: - /foo.model.json - context: {} + context: + emit_legacy_scripts: true name: foo class_name: IntValue properties: @@ -20,7 +21,8 @@ children: metadata: ignore_unknown_instances: false relevant_paths: [] - context: {} + context: + emit_legacy_scripts: true 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__class_client_from_vfs.snap similarity index 90% 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 index 40b4bbe21..5f5f6e9a1 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__class_client_from_vfs.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.client.lua - /foo.meta.json - context: {} + context: + emit_legacy_scripts: true name: foo class_name: LocalScript 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__class_module_from_vfs.snap similarity index 89% 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 index 6877e9a92..de2471b9a 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__class_module_from_vfs.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.lua - /foo.meta.json - context: {} + context: + emit_legacy_scripts: true 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__class_module_with_meta.snap similarity index 89% 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 index 8dcc57a97..32d70c708 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__class_module_with_meta.snap @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.lua - /foo.meta.json - context: {} + context: + emit_legacy_scripts: true 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__class_script_disabled.snap similarity index 85% 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 index 3f0408771..2c5546a53 100644 --- 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 @@ -10,12 +10,15 @@ metadata: relevant_paths: - /bar.server.lua - /bar.meta.json - context: {} + context: + emit_legacy_scripts: true 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__class_script_with_meta.snap similarity index 84% 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 index 6bdd2a385..e4e31ff96 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__class_script_with_meta.snap @@ -10,10 +10,13 @@ metadata: relevant_paths: - /foo.server.lua - /foo.meta.json - context: {} + context: + emit_legacy_scripts: true 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__class_server_from_vfs.snap similarity index 84% 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 index 63d33a0a4..b70b9cc2b 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__class_server_from_vfs.snap @@ -10,10 +10,13 @@ metadata: relevant_paths: - /foo.server.lua - /foo.meta.json - context: {} + context: + emit_legacy_scripts: true 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__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__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..6ad72d084 --- /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: + emit_legacy_scripts: false +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..83be811be --- /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: + emit_legacy_scripts: false +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..98a88ec7f --- /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: + emit_legacy_scripts: false +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..c47b83dc3 --- /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: + emit_legacy_scripts: false +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..72d24206f --- /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: + emit_legacy_scripts: false +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..2b902f964 --- /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: + emit_legacy_scripts: false +name: foo +class_name: Script +properties: + RunContext: + Enum: 1 + 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..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 @@ -9,7 +9,8 @@ metadata: Path: /foo/hello.project.json relevant_paths: - /foo/hello.project.json - context: {} + context: + emit_legacy_scripts: true 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..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 @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo/other.project.json - /foo/default.project.json - context: {} + context: + 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 b50eb1be7..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 @@ -9,7 +9,8 @@ metadata: Path: /foo.project.json relevant_paths: - /foo.project.json - context: {} + context: + emit_legacy_scripts: true name: children class_name: Folder properties: {} @@ -24,7 +25,8 @@ children: - $className: Model - Folder relevant_paths: [] - context: {} + context: + 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 d64a46e78..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 @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo/other.project.json - /foo/default.project.json - context: {} + context: + 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 0ceb043ab..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 @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo/other.project.json - /foo/default.project.json - context: {} + context: + emit_legacy_scripts: true name: path-child-project class_name: Folder properties: {} @@ -25,7 +26,8 @@ children: - $className: Model - Folder relevant_paths: [] - context: {} + context: + 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 51a222f93..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 @@ -11,7 +11,8 @@ metadata: - /foo/other.txt - /foo/other.meta.json - /foo/default.project.json - context: {} + context: + 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 9b8e91efd..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 @@ -9,7 +9,8 @@ metadata: Path: /foo.project.json relevant_paths: - /foo.project.json - context: {} + context: + 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 a07300bba..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 @@ -9,7 +9,8 @@ metadata: Path: /foo.project.json relevant_paths: - /foo.project.json - context: {} + context: + 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 3529bf896..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 @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.toml - /foo.meta.json - context: {} + context: + 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 b8a8d4afe..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 @@ -10,7 +10,8 @@ metadata: relevant_paths: - /foo.txt - /foo.meta.json - context: {} + context: + 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) +} 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, 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) + ); + }); }); }