Skip to content

Commit

Permalink
refactor: PackageManagerKind variant names
Browse files Browse the repository at this point in the history
  • Loading branch information
nokazn committed Feb 10, 2024
1 parent 73176b7 commit e93f268
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ use strum_macros::EnumIter;

#[derive(EnumIter, Serialize, Deserialize, Hash, Clone, Copy, Debug)]
pub enum PackageManagerKind {
PackageLock,
YarnLock,
PnpmLock,
BunLockb,
Npm,
Yarn,
Pnpm,
Bun,
}

impl PackageManagerKind {
pub fn file_names(&self) -> Vec<&str> {
match self {
PackageManagerKind::PackageLock => vec!["package-lock.json"],
PackageManagerKind::YarnLock => vec!["yarn.lock"],
PackageManagerKind::PnpmLock => vec!["pnpm-lock.yaml", "pnpm-lock.yml"],
PackageManagerKind::BunLockb => vec!["bun.lockb"],
PackageManagerKind::Npm => vec!["package-lock.json"],
PackageManagerKind::Yarn => vec!["yarn.lock"],
PackageManagerKind::Pnpm => vec!["pnpm-lock.yaml", "pnpm-lock.yml"],
PackageManagerKind::Bun => vec!["bun.lockb"],
}
}
}
4 changes: 2 additions & 2 deletions src/package_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ impl WorkspacePackage {
fn validate_package_json_fields<T: AsRef<Path>>(self, base_dir: T) -> Result<Self, Error> {
let package_json_path = to_package_json_path(&base_dir);
match self.kind {
PackageManagerKind::YarnLock
PackageManagerKind::Yarn
if self.original.name.is_none() || self.original.version.is_none() =>
{
Err(Error::InvalidPackageJsonFieldsForYarnError(
package_json_path,
))
}
PackageManagerKind::BunLockb if self.original.name.is_none() => Err(
PackageManagerKind::Bun if self.original.name.is_none() => Err(
Error::InvalidPackageJsonFieldsForBunError(package_json_path),
),
_ => Ok(self),
Expand Down
8 changes: 4 additions & 4 deletions src/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ impl Workspaces {
Self {
kind: kind,
packages: match &kind {
PackageManagerKind::PackageLock => Workspaces::resolve_npm_workspaces(base_dir, patterns),
PackageManagerKind::BunLockb => Workspaces::resolve_bun_workspaces(base_dir, patterns),
PackageManagerKind::YarnLock => Workspaces::resolve_yarn_workspaces(base_dir, patterns),
PackageManagerKind::PnpmLock => Workspaces::resolve_pnpm_workspaces(base_dir),
PackageManagerKind::Npm => Workspaces::resolve_npm_workspaces(base_dir, patterns),
PackageManagerKind::Bun => Workspaces::resolve_bun_workspaces(base_dir, patterns),
PackageManagerKind::Yarn => Workspaces::resolve_yarn_workspaces(base_dir, patterns),
PackageManagerKind::Pnpm => Workspaces::resolve_pnpm_workspaces(base_dir),
},
}
}
Expand Down

0 comments on commit e93f268

Please sign in to comment.