From fb1f07e777e89bb51a9f678223b1a6b3466a8237 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 4 Mar 2024 20:31:27 +0100 Subject: [PATCH] fix: allow package names up to 32 chars long (#177) Fixes #114 --- api/src/ids.rs | 15 +++++++++------ frontend/docs/publishing-packages.md | 2 +- frontend/islands/new.tsx | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/api/src/ids.rs b/api/src/ids.rs index 3480a2d0..ab3797eb 100644 --- a/api/src/ids.rs +++ b/api/src/ids.rs @@ -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)] @@ -156,7 +156,7 @@ impl PackageName { return Err(PackageNameValidateError::TooShort); } - if name.len() > 20 { + if name.len() > 32 { return Err(PackageNameValidateError::TooLong); } @@ -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")] @@ -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()); @@ -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()); diff --git a/frontend/docs/publishing-packages.md b/frontend/docs/publishing-packages.md index b0ad6e67..5d6ba614 100644 --- a/frontend/docs/publishing-packages.md +++ b/frontend/docs/publishing-packages.md @@ -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. diff --git a/frontend/islands/new.tsx b/frontend/islands/new.tsx index 09c40dfe..4291641f 100644 --- a/frontend/islands/new.tsx +++ b/frontend/islands/new.tsx @@ -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.";