Tightened project discovery behavior

This commit is contained in:
Lucien Greathouse
2019-11-02 23:36:28 -07:00
parent 7c71708de7
commit 3a538f98ed
3 changed files with 23 additions and 26 deletions

View File

@@ -14,6 +14,9 @@
* Added support for automatically finding Roblox Studio's auth cookie for `rojo upload` on Windows.
* Added support for building, serving and uploading sources that aren't Rojo projects.
* Improved feedback from `rojo serve`.
* Removed support for legacy `roblox-project.json` projects, deprecated in an early Rojo 0.5.0 alpha.
* Rojo no longer traverses directories upwards looking for project files.
* Though undocumented, Rojo 0.5.x will search for a project file contained in any ancestor folders. This feature was removed to better support other 0.6.x features.
### Roblox Studio Plugin
* Added "connecting" state to improve experience when live syncing.

View File

@@ -432,31 +432,33 @@ impl Project {
Ok(project_path)
}
fn locate(start_location: &Path) -> Option<PathBuf> {
// TODO: Check for specific error kinds, convert 'not found' to Result.
let location_metadata = fs::metadata(start_location).ok()?;
/// Attempt to locate a project represented by the given path.
///
/// This will find a project if the path refers to a `.project.json` file,
/// or is a folder that contains a `default.project.json` file.
fn locate(path: &Path) -> Option<PathBuf> {
let meta = fs::metadata(path).ok()?;
// If this is a file, assume it's the config the user was looking for.
if location_metadata.is_file() {
if Project::is_project_file(start_location) {
return Some(start_location.to_path_buf());
if meta.is_file() {
if Project::is_project_file(path) {
Some(path.to_path_buf())
} else {
return None;
None
}
} else {
let with_file = start_location.join(PROJECT_FILENAME);
let child_path = path.join(PROJECT_FILENAME);
let child_meta = fs::metadata(&child_path).ok()?;
if let Ok(file_metadata) = fs::metadata(&with_file) {
if file_metadata.is_file() {
return Some(with_file);
}
if child_meta.is_file() {
Some(child_path)
} else {
// This is a folder with the same name as a Rojo default project
// file.
//
// That's pretty weird, but we can roll with it.
None
}
}
match start_location.parent() {
Some(parent_location) => Self::locate(parent_location),
None => None,
}
}
fn load_from_str(

View File

@@ -16,14 +16,6 @@ lazy_static! {
{ Path::new(env!("CARGO_MANIFEST_DIR")).join("test-projects") };
}
#[test]
fn empty() {
let project_file_location = TEST_PROJECTS_ROOT.join("empty/default.project.json");
let project = Project::load_exact(&project_file_location).unwrap();
assert_eq!(project.name, "empty");
}
#[test]
fn empty_fuzzy_file() {
let project_file_location = TEST_PROJECTS_ROOT.join("empty/default.project.json");