mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-21 21:25:16 +00:00
Defer application of init.meta.json until after init Lua files. (#549)
Fixes #546.
This commit is contained in:
committed by
GitHub
parent
c06463b61d
commit
e5dbee1073
@@ -10,6 +10,40 @@ pub fn snapshot_dir(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
path: &Path,
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let mut snapshot = match snapshot_dir_no_meta(context, vfs, path)? {
|
||||
Some(snapshot) => snapshot,
|
||||
None => return Ok(None),
|
||||
};
|
||||
|
||||
if let Some(mut meta) = dir_meta(vfs, path)? {
|
||||
meta.apply_all(&mut snapshot)?;
|
||||
}
|
||||
|
||||
Ok(Some(snapshot))
|
||||
}
|
||||
|
||||
/// Retrieves the meta file that should be applied for this directory, if it
|
||||
/// exists.
|
||||
pub fn dir_meta(vfs: &Vfs, path: &Path) -> anyhow::Result<Option<DirectoryMetadata>> {
|
||||
let meta_path = path.join("init.meta.json");
|
||||
|
||||
if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? {
|
||||
let metadata = DirectoryMetadata::from_slice(&meta_contents, meta_path)?;
|
||||
Ok(Some(metadata))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Snapshot a directory without applying meta files; useful for if the
|
||||
/// directory's ClassName will change before metadata should be applied. For
|
||||
/// example, this can happen if the directory contains an `init.client.lua`
|
||||
/// file.
|
||||
pub fn snapshot_dir_no_meta(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
path: &Path,
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let passes_filter_rules = |child: &DirEntry| {
|
||||
context
|
||||
@@ -52,7 +86,7 @@ pub fn snapshot_dir(
|
||||
path.join("init.client.lua"),
|
||||
];
|
||||
|
||||
let mut snapshot = InstanceSnapshot::new()
|
||||
let snapshot = InstanceSnapshot::new()
|
||||
.name(instance_name)
|
||||
.class_name("Folder")
|
||||
.children(snapshot_children)
|
||||
@@ -63,11 +97,6 @@ pub fn snapshot_dir(
|
||||
.context(context),
|
||||
);
|
||||
|
||||
if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? {
|
||||
let mut metadata = DirectoryMetadata::from_slice(&meta_contents, meta_path)?;
|
||||
metadata.apply_all(&mut snapshot)?;
|
||||
}
|
||||
|
||||
Ok(Some(snapshot))
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,11 @@ use memofs::{IoResultExt, Vfs};
|
||||
|
||||
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
|
||||
|
||||
use super::{dir::snapshot_dir, meta_file::AdjacentMetadata, util::match_trailing};
|
||||
use super::{
|
||||
dir::{dir_meta, snapshot_dir_no_meta},
|
||||
meta_file::AdjacentMetadata,
|
||||
util::match_trailing,
|
||||
};
|
||||
|
||||
/// Core routine for turning Lua files into snapshots.
|
||||
pub fn snapshot_lua(
|
||||
@@ -66,7 +70,7 @@ pub fn snapshot_lua_init(
|
||||
init_path: &Path,
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let folder_path = init_path.parent().unwrap();
|
||||
let dir_snapshot = snapshot_dir(context, vfs, folder_path)?.unwrap();
|
||||
let dir_snapshot = snapshot_dir_no_meta(context, vfs, folder_path)?.unwrap();
|
||||
|
||||
if dir_snapshot.class_name != "Folder" {
|
||||
anyhow::bail!(
|
||||
@@ -86,6 +90,10 @@ pub fn snapshot_lua_init(
|
||||
init_snapshot.children = dir_snapshot.children;
|
||||
init_snapshot.metadata = dir_snapshot.metadata;
|
||||
|
||||
if let Some(mut meta) = dir_meta(vfs, folder_path)? {
|
||||
meta.apply_all(&mut init_snapshot)?;
|
||||
}
|
||||
|
||||
Ok(Some(init_snapshot))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user