Correct issue with default.project.json files with no name being named default after change (#917)

Co-authored-by: Kenneth Loeffler <kenloef@gmail.com>
This commit is contained in:
Micah
2024-07-15 09:24:51 -07:00
committed by GitHub
parent 7e2bab921a
commit 3ca975d81d
13 changed files with 244 additions and 76 deletions

View File

@@ -63,6 +63,9 @@ pub fn snapshot_from_vfs(
if meta.is_dir() {
if let Some(init_path) = get_init_path(vfs, path)? {
// TODO: support user-defined init paths
// If and when we do, make sure to go support it in
// `Project::set_file_name`, as right now it special-cases
// `default.project.json` as an `init` path.
for rule in default_sync_rules() {
if rule.matches(&init_path) {
return match rule.middleware {
@@ -274,7 +277,7 @@ macro_rules! sync_rule {
/// Defines the 'default' syncing rules that Rojo uses.
/// These do not broadly overlap, but the order matters for some in the case of
/// e.g. JSON models.
fn default_sync_rules() -> &'static [SyncRule] {
pub fn default_sync_rules() -> &'static [SyncRule] {
static DEFAULT_SYNC_RULES: OnceLock<Vec<SyncRule>> = OnceLock::new();
DEFAULT_SYNC_RULES.get_or_init(|| {

View File

@@ -22,9 +22,12 @@ pub fn snapshot_project(
path: &Path,
name: &str,
) -> anyhow::Result<Option<InstanceSnapshot>> {
let project = Project::load_from_slice(&vfs.read(path)?, path)
let project = Project::load_exact(vfs, path, Some(name))
.with_context(|| format!("File was not a valid Rojo project: {}", path.display()))?;
let project_name = project.name.as_deref().unwrap_or(name);
let project_name = match project.name.as_deref() {
Some(name) => name,
None => panic!("Project is missing a name"),
};
let mut context = context.clone();
context.clear_sync_rules();

View File

@@ -1,6 +1,5 @@
---
source: src/snapshot_middleware/project.rs
assertion_line: 730
expression: instance_snapshot
---
snapshot_id: "00000000000000000000000000000000"
@@ -13,7 +12,7 @@ metadata:
context:
emit_legacy_scripts: true
specified_id: ~
name: no_name_project
name: foo
class_name: Model
properties: {}
children: []