diff --git a/CHANGELOG.md b/CHANGELOG.md index d7782a5c..b5a07828 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,10 @@ Making a new release? Simply add the new header with the version and date undern ## Unreleased +* Fixed a bug where `$path` in an instance description couldn't reference an init script directly (i.e init.luau, init.sever.luau, etc). ([#1285]) + +[#1285]: https://github.com/rojo-rbx/rojo/pull/1285 + ## [7.7.1] (October 1st, 2026) * Fixed `$path` values that point outside the project folder failing to match `syncRule`s on Windows, which broke `rojo sourcemap` with a "could not be turned into a Roblox Instance" error. ([#1290]) diff --git a/rojo-test/build-test-snapshots/end_to_end__tests__build__init_from_path.snap b/rojo-test/build-test-snapshots/end_to_end__tests__build__init_from_path.snap new file mode 100644 index 00000000..7f446250 --- /dev/null +++ b/rojo-test/build-test-snapshots/end_to_end__tests__build__init_from_path.snap @@ -0,0 +1,18 @@ +--- +source: tests/tests/build.rs +expression: contents +--- + + + + init_from_path + + + + folder + + + + + diff --git a/rojo-test/build-tests/init_from_path/default.project.json b/rojo-test/build-tests/init_from_path/default.project.json new file mode 100644 index 00000000..aecd9d65 --- /dev/null +++ b/rojo-test/build-tests/init_from_path/default.project.json @@ -0,0 +1,9 @@ +{ + "name": "init_from_path", + "tree": { + "$className": "Folder", + "folder": { + "$path": "folder/init.luau" + } + } +} \ No newline at end of file diff --git a/rojo-test/build-tests/init_from_path/folder/ignore_me.luau b/rojo-test/build-tests/init_from_path/folder/ignore_me.luau new file mode 100644 index 00000000..0b5801fc --- /dev/null +++ b/rojo-test/build-tests/init_from_path/folder/ignore_me.luau @@ -0,0 +1 @@ +-- ignore_me.luau diff --git a/rojo-test/build-tests/init_from_path/folder/init.luau b/rojo-test/build-tests/init_from_path/folder/init.luau new file mode 100644 index 00000000..bbc821f4 --- /dev/null +++ b/rojo-test/build-tests/init_from_path/folder/init.luau @@ -0,0 +1 @@ +-- init.luau diff --git a/src/snapshot_middleware/dir.rs b/src/snapshot_middleware/dir.rs index b9f62743..2ff0b6bf 100644 --- a/src/snapshot_middleware/dir.rs +++ b/src/snapshot_middleware/dir.rs @@ -51,7 +51,7 @@ pub fn snapshot_dir_no_meta( for entry in vfs.read_dir(path)? { let entry = entry?; - if !passes_filter_rules(&entry) { + if !passes_filter_rules(&entry) || is_init_file(entry.path()).unwrap() { continue; } @@ -221,6 +221,21 @@ pub fn syncback_dir_no_meta<'sync>( }) } +fn is_init_file(path: &Path) -> anyhow::Result { + let file_name = path + .file_name() + .and_then(|n| n.to_str()) + .with_context(|| format!("file name of {} is invalid", path.display()))?; + + match file_name { + "init.server.luau" | "init.server.lua" | "init.client.luau" | "init.client.lua" + | "init.plugin.luau" | "init.plugin.lua" | "init.luau" | "init.lua" | "init.csv" => { + Ok(true) + } + _ => Ok(false), + } +} + #[cfg(test)] mod test { use super::*; diff --git a/src/snapshot_middleware/mod.rs b/src/snapshot_middleware/mod.rs index fadce5f6..b2c6faaf 100644 --- a/src/snapshot_middleware/mod.rs +++ b/src/snapshot_middleware/mod.rs @@ -72,32 +72,18 @@ pub fn snapshot_from_vfs( None => return Ok(None), }; - if meta.is_dir() { - let (middleware, dir_name, init_path) = get_dir_middleware(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. - match middleware { - Middleware::Dir => middleware.snapshot(context, vfs, path, dir_name), - _ => middleware.snapshot(context, vfs, &init_path, dir_name), - } - } else { - let file_name = path - .file_name() - .and_then(|n| n.to_str()) - .with_context(|| format!("file name of {} is invalid", path.display()))?; + if !meta.is_dir() { + return snapshot_from_path(context, vfs, path); + } - // TODO: Is this even necessary anymore? - match file_name { - "init.server.luau" | "init.server.lua" | "init.client.luau" | "init.client.lua" - | "init.plugin.luau" | "init.plugin.lua" | "init.luau" | "init.lua" | "init.csv" => { - return Ok(None) - } - _ => {} - } - - snapshot_from_path(context, vfs, path) + let (middleware, dir_name, init_path) = get_dir_middleware(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. + match middleware { + Middleware::Dir => middleware.snapshot(context, vfs, path, dir_name), + _ => middleware.snapshot(context, vfs, &init_path, dir_name), } } diff --git a/tests/tests/build.rs b/tests/tests/build.rs index c7873050..56315e42 100644 --- a/tests/tests/build.rs +++ b/tests/tests/build.rs @@ -66,6 +66,7 @@ gen_build_tests! { no_name_project, no_name_top_level_project, plugin_init, + init_from_path, } fn run_build_test(test_name: &str) {