Add Support for Plugin Scripts (#1008)

This commit is contained in:
Sasial
2025-04-03 04:37:49 +10:00
committed by GitHub
parent 833320de64
commit 73ed5ae697
4 changed files with 54 additions and 0 deletions

View File

@@ -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();

View File

@@ -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"),

View File

@@ -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: []