pub fn infer(reference_dir: &AbsoluteSystemPath) -> Result<Self, Error> {
        reference_dir
            .ancestors()
            .filter_map(|path| {
                PackageJson::load(&path.join_component("package.json"))
                    .ok()
                    .map(|package_json| {
                        // FIXME: We should save this package manager that we detected
                        let package_manager =
                            PackageManager::read_or_detect_package_manager(&package_json, path);
                        let workspace_globs = package_manager
                            .as_ref()
                            .ok()
                            .and_then(|mgr| mgr.get_workspace_globs(path).ok());

                        InferInfo {
                            path: path.to_owned(),
                            workspace_globs,
                            package_manager,
                            package_json,
                        }
                    })
            })
            .reduce(|current, candidate| {
                if current.repo_mode() == RepoMode::MultiPackage {
                    // We already have a multi-package root, go with that
                    current
                } else if candidate.is_workspace_root_of(&current.path) {
                    // The next candidate is a multipackage root, and it contains current so it's
                    // our root.
                    candidate
                } else {
                    // keep the current single package, it's the closest in
                    current
                }
            })
            .map(|root| root.into())
            .ok_or_else(|| Error::NotFound(reference_dir.to_owned()))
    }
Infers `RepoState` from a reference path

# Arguments

* `reference_dir`: Turbo's invocation directory

returns: Result<RepoState, Error>
crates/turborepo-repository/src/inference.rs