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