Skip to content

Commit

Permalink
fix: support max package length of 58 (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato authored Feb 2, 2025
1 parent da68eb3 commit 6cf4491
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
15 changes: 9 additions & 6 deletions api/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ pub enum ScopeNameValidateError {
}

/// A package name, like 'foo' or 'bar'. The name is not prefixed with an @.
/// The name must be at least 2 character long, and at most 32 characters long.
/// The name must be at least 2 character long, and at most 58 characters long.
/// The name must only contain alphanumeric characters and hyphens.
/// The name must not start or end with a hyphen.
///
/// 1 (@) + 20 (scope name) + 1 (/) + 58 (package name) = 80
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct PackageName(String);

Expand All @@ -157,7 +159,7 @@ impl PackageName {
return Err(PackageNameValidateError::TooShort);
}

if name.len() > 32 {
if name.len() > 58 {
return Err(PackageNameValidateError::TooLong);
}

Expand Down Expand Up @@ -270,7 +272,7 @@ pub enum PackageNameValidateError {
#[error("package name must be at least 2 characters long")]
TooShort,

#[error("package name must be at most 32 characters long")]
#[error("package name must be at most 58 characters long")]
TooLong,

#[error("package name must contain only lowercase ascii alphanumeric characters and hyphens")]
Expand Down Expand Up @@ -897,9 +899,10 @@ mod tests {
assert!(PackageName::try_from("f").is_err());
assert!(PackageName::try_from("Foo").is_err());
assert!(PackageName::try_from("oooF").is_err());
assert!(
PackageName::try_from("very-long-name-is-very-very-very-long").is_err()
);
assert!(PackageName::try_from(
"very-long-name-is-very-very-very-very-very-very-very-very-long"
)
.is_err());
assert!(PackageName::try_from("foo_bar").is_err());
assert!(PackageName::try_from("-foo").is_err());
assert!(PackageName::try_from("foo-").is_err());
Expand Down
2 changes: 1 addition & 1 deletion frontend/docs/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ by an author to the JSR site. Scopes are similar to npm organizations or GitHub
accounts. [Learn more about scopes.](/docs/scopes)

Packages have a name. Package names are unique within a scope - no two packages
in the same scope can have the same name. Package names must be between 2 and 20
in the same scope can have the same name. Package names must be between 2 and 58
characters long, and can only contain lowercase letters, numbers, and hyphens.
They cannot start with a hyphen.

Expand Down
4 changes: 2 additions & 2 deletions frontend/islands/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ export function PackageName(
if (name.value.startsWith("@")) {
return "Enter only the package name, do not include the scope.";
}
if (name.value.length > 32) {
return "Package name cannot be longer than 32 characters.";
if (name.value.length > 58) {
return "Package name cannot be longer than 58 characters.";
}
if (!/^[a-z0-9\-]+$/.test(name.value)) {
return "Package name can only contain lowercase letters, numbers, and hyphens.";
Expand Down

0 comments on commit 6cf4491

Please sign in to comment.