Skip to content

Commit

Permalink
fix: allow package names up to 32 chars long (#177)
Browse files Browse the repository at this point in the history
Fixes #114
  • Loading branch information
lucacasonato authored Mar 4, 2024
1 parent a59b466 commit fb1f07e
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 @@ -144,7 +144,7 @@ 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 20 characters long.
/// The name must be at least 2 character long, and at most 32 characters long.
/// The name must only contain alphanumeric characters and hyphens.
/// The name must not start or end with a hyphen.
#[derive(Clone, PartialEq, Eq, Hash)]
Expand All @@ -156,7 +156,7 @@ impl PackageName {
return Err(PackageNameValidateError::TooShort);
}

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

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

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

#[error("package name must contain only lowercase ascii alphanumeric characters and hyphens")]
Expand Down Expand Up @@ -790,8 +790,8 @@ mod tests {
// Test invalid scope names
assert!(ScopeName::try_from("").is_err());
assert!(ScopeName::try_from("f").is_err());
assert!(PackageName::try_from("Foo").is_err());
assert!(PackageName::try_from("oooF").is_err());
assert!(ScopeName::try_from("Foo").is_err());
assert!(ScopeName::try_from("oooF").is_err());
assert!(ScopeName::try_from("very-long-name-is-very-long").is_err());
assert!(ScopeName::try_from("123").is_err());
assert!(ScopeName::try_from("1oo").is_err());
Expand All @@ -817,13 +817,16 @@ mod tests {
assert!(PackageName::try_from("foo-123-bar").is_ok());
assert!(PackageName::try_from("f123").is_ok());
assert!(PackageName::try_from("foo-bar-baz-qux").is_ok());
assert!(PackageName::try_from("very-long-name-is-very-long").is_ok());

// Test invalid package names
assert!(PackageName::try_from("").is_err());
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-long").is_err());
assert!(
PackageName::try_from("very-long-name-is-very-very-very-long").is_err()
);
assert!(PackageName::try_from("123").is_err());
assert!(PackageName::try_from("1oo").is_err());
assert!(PackageName::try_from("123-foo").is_err());
Expand Down
2 changes: 1 addition & 1 deletion frontend/docs/publishing-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ similar to npm organizations. Scopes are prefixed with an `@` symbol, and are
followed by a name. For example, `@luca` is a scope.

You can create a scope at [jsr.io/new](/new). Scopes names must be between 2 and
20 characters long, and can only contain lowercase letters, numbers, and
32 characters long, and can only contain lowercase letters, numbers, and
hyphens. You can only create a scope if the name is not already taken. Scope
names that are very similar to existing scope names -- for example ones that
only differ by a hyphen -- are prohibited.
Expand Down
4 changes: 2 additions & 2 deletions frontend/islands/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ export function PackageName(
const message = useComputed(() => {
if (error.value) return error.value;
if (name.value.length === 0) return "";
if (name.value.length > 20) {
return "Package name cannot be longer than 20 characters.";
if (name.value.length > 32) {
return "Package name cannot be longer than 32 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 fb1f07e

Please sign in to comment.