From 73ed5ae697ce42fa4204e8d0c1e122bf54f2df6f Mon Sep 17 00:00:00 2001 From: Sasial <44125644+sasial-dev@users.noreply.github.com> Date: Thu, 3 Apr 2025 04:37:49 +1000 Subject: [PATCH] Add Support for Plugin Scripts (#1008) --- CHANGELOG.md | 2 ++ src/snapshot_middleware/lua.rs | 25 +++++++++++++++++++ src/snapshot_middleware/mod.rs | 4 +++ ...re__lua__test__plugin_module_from_vfs.snap | 23 +++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__plugin_module_from_vfs.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index 42a6968e..ed501ab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Rojo Changelog ## Unreleased Changes +* Adds support for `.plugin.lua(u)` files - this applies the `Plugin` RunContext. ([#1008]) * Added support for Roblox's `Content` type. This replaces the old `Content` type with `ContentId` to reflect Roblox's change. If you were previously using the fully-qualified syntax for `Content` you will need to switch it to `ContentId`. * Added support for `Enum` attributes @@ -95,6 +96,7 @@ [#974]: https://github.com/rojo-rbx/rojo/pull/974 [#987]: https://github.com/rojo-rbx/rojo/pull/987 [#988]: https://github.com/rojo-rbx/rojo/pull/988 +[#1008]: https://github.com/rojo-rbx/rojo/pull/1008 ## [7.4.3] - August 6th, 2024 * Fixed issue with building binary files introduced in 7.4.2 diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 3300dfb6..bad2550f 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -15,6 +15,7 @@ pub enum ScriptType { Server, Client, Module, + Plugin, } /// Core routine for turning Lua files into snapshots. @@ -37,6 +38,7 @@ pub fn snapshot_lua( (true, ScriptType::Server) => ("Script", run_context_enums.get("Legacy")), (true, ScriptType::Client) => ("LocalScript", None), (_, ScriptType::Module) => ("ModuleScript", None), + (_, ScriptType::Plugin) => ("Script", run_context_enums.get("Plugin")), }; let contents = vfs.read_to_string_lf_normalized(path)?; @@ -164,6 +166,29 @@ mod test { }); } + #[test] + fn plugin_module_from_vfs() { + let mut imfs = InMemoryFs::new(); + imfs.load_snapshot("/foo.plugin.lua", VfsSnapshot::file("Hello there!")) + .unwrap(); + + let vfs = Vfs::new(imfs); + + let instance_snapshot = snapshot_lua( + &InstanceContext::with_emit_legacy_scripts(Some(false)), + &vfs, + Path::new("/foo.plugin.lua"), + "foo", + ScriptType::Plugin, + ) + .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(); diff --git a/src/snapshot_middleware/mod.rs b/src/snapshot_middleware/mod.rs index 410d96ec..da16c7a0 100644 --- a/src/snapshot_middleware/mod.rs +++ b/src/snapshot_middleware/mod.rs @@ -202,6 +202,7 @@ pub enum Middleware { ServerScript, ClientScript, ModuleScript, + PluginScript, Project, Rbxm, Rbxmx, @@ -227,6 +228,7 @@ impl Middleware { Self::ServerScript => snapshot_lua(context, vfs, path, name, ScriptType::Server), Self::ClientScript => snapshot_lua(context, vfs, path, name, ScriptType::Client), Self::ModuleScript => snapshot_lua(context, vfs, path, name, ScriptType::Module), + Self::PluginScript => snapshot_lua(context, vfs, path, name, ScriptType::Plugin), Self::Project => snapshot_project(context, vfs, path, name), Self::Rbxm => snapshot_rbxm(context, vfs, path, name), Self::Rbxmx => snapshot_rbxmx(context, vfs, path, name), @@ -286,6 +288,8 @@ pub fn default_sync_rules() -> &'static [SyncRule] { sync_rule!("*.server.luau", ServerScript, ".server.luau"), sync_rule!("*.client.lua", ClientScript, ".client.lua"), sync_rule!("*.client.luau", ClientScript, ".client.luau"), + sync_rule!("*.plugin.lua", PluginScript, ".plugin.lua"), + sync_rule!("*.plugin.luau", PluginScript, ".plugin.luau"), sync_rule!("*.{lua,luau}", ModuleScript), sync_rule!("*.project.json", Project, ".project.json"), sync_rule!("*.model.json", JsonModel, ".model.json"), diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__plugin_module_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__plugin_module_from_vfs.snap new file mode 100644 index 00000000..8f88f38e --- /dev/null +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__plugin_module_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.plugin.lua + relevant_paths: + - /foo.plugin.lua + - /foo.meta.json + context: + emit_legacy_scripts: false + specified_id: ~ +name: foo +class_name: Script +properties: + RunContext: + Enum: 3 + Source: + String: Hello there! +children: []