Skip to content

Commit

Permalink
wip: add workspaces to manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Oct 8, 2024
1 parent 8c3c96d commit 9cf4853
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::{
#[allow(clippy::print_stdout)]
fn main() -> Result<()> {
pretty_env_logger::init();
let matches = cli();
let opts = CliOptions::new(matches).and_then(OxbuildOptions::new)?;
let cli_args = CliOptions::new(cli())?;
let opts = OxbuildOptions::new(cli_args)?;
let num_threads = opts.num_threads.get();

let (mut reporter, report_sender) = Reporter::new();
Expand Down
9 changes: 9 additions & 0 deletions src/workspace/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use miette::{Context as _, IntoDiagnostic as _, Result};
use package_json::PackageJson;
use tsconfig::TsConfig;

use super::workspace_globs::Workspaces;

/// A package manifest.
///
/// May be a single package, a package in a monorepo, or the monorepo root itself.
Expand All @@ -12,6 +14,7 @@ pub struct Manifest {
dir: PathBuf,
package_json: PackageJson,
tsconfig: Option<TsConfig>,
workspaces: Option<Workspaces>,
}

impl Manifest {
Expand Down Expand Up @@ -51,10 +54,16 @@ impl Manifest {
)
})?;

let workspaces = package_json
.workspaces
.as_ref()
.map(|workspaces| Workspaces::from_iter(workspaces));

Ok(Self {
dir: package_folder,
package_json,
tsconfig,
workspaces,
})
}
}
24 changes: 14 additions & 10 deletions src/workspace/workspace_globs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ use thiserror::{self, Error};
///
/// Supports exclusion patterns (starting with `!`).
#[derive(Debug, Clone)]
pub struct Workspaces {
pub(super) include_globs: Vec<CompactString>,
pub(super) exclude_globs: Option<Vec<CompactString>>,
pub struct Workspaces<S = CompactString> {
pub(super) include_globs: Vec<S>,
pub(super) exclude_globs: Option<Vec<S>>,
// nohoist
}
impl<S: AsRef<str>> FromIterator<S> for Workspaces {

impl<S: AsRef<str>> FromIterator<S> for Workspaces<CompactString> {
fn from_iter<T: IntoIterator<Item = S>>(iter: T) -> Self {
let globs = iter.into_iter();
let hint = globs.size_hint();
Expand Down Expand Up @@ -51,21 +52,21 @@ impl<S: AsRef<str>> FromIterator<S> for Workspaces {
}
}

impl Workspaces {
pub fn new(include: Vec<CompactString>, exclude: Option<Vec<CompactString>>) -> Self {
impl<S: AsRef<str> + AsRef<Path> + ToString> Workspaces<S> {
pub fn new(include: Vec<S>, exclude: Option<Vec<S>>) -> Self {
Self {
include_globs: include,
exclude_globs: exclude,
}
}

/// Glob patterns of packages to include in the workspace
pub fn included(&self) -> &[CompactString] {
pub fn included(&self) -> &[S] {
self.include_globs.as_slice()
}

/// Glob patterns of packages to exclude from the workspace
pub fn excluded(&self) -> Option<&[CompactString]> {
pub fn excluded(&self) -> Option<&[S]> {
self.exclude_globs.as_deref()
}

Expand Down Expand Up @@ -108,7 +109,10 @@ struct WorkspaceIter {
}

impl WorkspaceIter {
fn new(root: &Path, workspaces: &Workspaces) -> (Self, Vec<BadGlobError>) {
fn new<S: AsRef<Path> + AsRef<str> + ToString>(
root: &Path,
workspaces: &Workspaces<S>,
) -> (Self, Vec<BadGlobError>) {
let included = workspaces.included();
let mut include = Vec::with_capacity(included.len());
let mut errors = Vec::with_capacity(included.len());
Expand All @@ -135,7 +139,7 @@ impl WorkspaceIter {
let exclude = workspaces.excluded().map(|exclude| {
let mut exclude_patterns = Vec::with_capacity(exclude.len());
for raw_pattern in exclude {
match Pattern::new(raw_pattern) {
match Pattern::new(raw_pattern.as_ref()) {
Ok(pattern) => exclude_patterns.push(pattern),
Err(e) => errors.push(BadGlobError::bad_pattern(
raw_pattern.to_string(),
Expand Down

0 comments on commit 9cf4853

Please sign in to comment.