Skip to content

Commit

Permalink
Converting more errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Jun 4, 2024
1 parent 56ccc9a commit c0fd54d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<'a> DependencyVersion<'a> {
_ => {
// If we got this far, then we need to check the workspace package version to
// see it satisfies the dependencies range to determin whether
// or not its an internal or external dependency.
// or not it's an internal or external dependency.
let constraint = node_semver::Range::parse(self.version);
let version = node_semver::Version::parse(package_version);

Expand Down
22 changes: 19 additions & 3 deletions crates/turborepo-repository/src/package_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,16 @@ pub enum Error {
#[error("We detected multiple package managers in your repository: {}. Please remove one \
of them.", managers.join(", "))]
MultiplePackageManagers { managers: Vec<String> },
#[error(transparent)]
Semver(#[from] node_semver::SemverError),
//#[error(transparent)]
//Semver(#[from] node_semver::SemverError),
#[error("invalid semantic version `{version}`")]
InvalidVersion {
version: String,
#[label("version found here")]
span: Option<SourceSpan>,
#[source_code]
text: NamedSource,
},
#[error("{0}: {1}")]
// this will be something like "cannot find binary: <thing we tried to find>"
Which(which::Error, String),
Expand Down Expand Up @@ -438,7 +446,15 @@ impl PackageManager {
};

let (manager, version) = Self::parse_package_manager_string(package_manager)?;
let version = version.parse()?;
let version = version.parse().map_err(|_| {
let (span, text) = package_manager.span_and_text("package.json");
Error::InvalidVersion {
version: version.to_string(),
span,
text,
}
})?;

match manager {
"npm" => Ok(PackageManager::Npm),
"bun" => Ok(PackageManager::Bun),
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-repository/src/package_manager/pnpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub struct PnpmDetector;

impl PnpmDetector {
pub fn detect_pnpm6_or_pnpm(version: &Version) -> Result<PackageManager, Error> {
let pnpm6_constraint: Range = "<7.0.0".parse()?;
let pnpm9_constraint: Range = ">=9.0.0-alpha.0".parse()?;
let pnpm6_constraint: Range = "<7.0.0".parse().expect("valid version");
let pnpm9_constraint: Range = ">=9.0.0-alpha.0".parse().expect("valid version");
if pnpm6_constraint.satisfies(version) {
Ok(PackageManager::Pnpm6)
} else if pnpm9_constraint.satisfies(version) {
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-repository/src/package_manager/yarn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct YarnDetector;

impl YarnDetector {
pub fn detect_berry_or_yarn(version: &Version) -> Result<PackageManager, Error> {
let berry_constraint: Range = ">=2.0.0-0".parse()?;
let berry_constraint: Range = ">=2.0.0-0".parse().expect("valid version");
if berry_constraint.satisfies(version) {
Ok(PackageManager::Berry)
} else {
Expand Down

0 comments on commit c0fd54d

Please sign in to comment.