async fn packages(&self, filter: Option<PackagePredicate>) -> Result<Array<Package>, Error> {
        let Some(filter) = filter else {
            let mut packages = self
                .run
                .pkg_dep_graph()
                .packages()
                .map(|(name, _)| Package::new(self.run.clone(), name.clone()))
                .collect::<Result<Array<_>, _>>()?;
            packages.sort_by(|a, b| a.get_name().cmp(b.get_name()));
            return Ok(packages);
        };

        let mut packages = self
            .run
            .pkg_dep_graph()
            .packages()
            .map(|(name, _)| Package::new(self.run.clone(), name.clone()))
            .filter(|pkg| pkg.as_ref().is_ok_and(|pkg| filter.check(pkg)))
            .collect::<Result<Array<_>, _>>()?;
        packages.sort_by(|a, b| a.get_name().cmp(b.get_name()));

        Ok(packages)
    }
Gets a list of packages that match the given filter
crates/turborepo-lib/src/query/mod.rs