Skip to content

Commit

Permalink
Merge branch 'main' into fix/copy-button-overlaps
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoder93 authored Jan 16, 2025
2 parents 0bbe69e + 8299130 commit 08d8154
Show file tree
Hide file tree
Showing 38 changed files with 682 additions and 251 deletions.
467 changes: 379 additions & 88 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ frontend in a development mode that connects to the production API.

- Clone this repo
- Install Deno (https://deno.land/#installation)
- Add the following to your `/etc/hosts`
- Add the following to your `/etc/hosts` file. If you're using WSL, you'll also
need to update the `hosts` file located at
`C:\Windows\System32\drivers\etc\hosts`.
```
127.0.0.1 jsr.test
127.0.0.1 api.jsr.test
Expand All @@ -71,7 +73,9 @@ making changes to the API.
- Clone this repo
- Install Deno (https://deno.land/#installation)
- Install Rust (https://rustup.rs/)
- Add the following to your `/etc/hosts`
- Add the following to your `/etc/hosts` file. If you're using WSL, you'll also
need to update the `hosts` file located at
`C:\Windows\System32\drivers\etc\hosts`.
```
127.0.0.1 jsr.test
127.0.0.1 api.jsr.test
Expand Down
16 changes: 8 additions & 8 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }
tokio-stream = "0.1"
url = "2"
url = "2.5.4"
uuid = { version = "1", features = ["v4", "serde"] }
clap = { version = "4", default-features = false, features = [
"derive",
Expand All @@ -74,13 +74,13 @@ opentelemetry = { version = "0.19", features = [
] }
opentelemetry-otlp = "0.12"
opentelemetry-gcloud-trace = "0.5.0"
deno_semver = "0.5.2"
deno_semver = "0.6.0"
flate2 = "1"
thiserror = "1"
thiserror = "2"
async-tar = "0.4.2"
deno_graph = "0.85.1"
deno_ast = { version = "0.43.3", features = ["view"] }
deno_doc = { version = "0.161.0", features = ["comrak"] }
deno_graph = "0.86.3"
deno_ast = { version = "0.44.0", features = ["view"] }
deno_doc = { version = "0.162.3", features = ["comrak"] }
comrak = { version = "0.29.0", default-features = false }
ammonia = "4.0.0"
async-trait = "0.1.73"
Expand All @@ -92,7 +92,7 @@ regex = "1.10.2"
postmark = { version = "=0.10.0", features = ["reqwest-rustls-tls"] }
handlebars = "5.0.0"
jsonc-parser = { version = "0.23", features = ["serde"] }
deno_npm = "0.25.0"
deno_npm = "0.26.0"
sha1 = "0.10.6"
infer = "0.15.0"
x509-parser = { version = "0.15.1", features = ["verify"] }
Expand All @@ -114,5 +114,5 @@ lazy_static = "1.5.0"

[dev-dependencies]
flate2 = "1"
deno_semver = "0.5.1"
deno_semver = "0.6.0"
pretty_assertions = "1.4.0"
2 changes: 1 addition & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This Dockerfile is adapted from https://whitfin.io/blog/speeding-up-rust-docker-builds/

FROM rust:1.77 as build
FROM rust:1.83 as build

# create a new empty shell project
RUN USER=root cargo new --bin registry_api
Expand Down
56 changes: 50 additions & 6 deletions api/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ async fn analyze_package_inner(
.analyzer
.get_parsed_source(module.specifier())
{
check_for_banned_extensions(&parsed_source)?;
check_for_banned_syntax(&parsed_source)?;
check_for_banned_triple_slash_directives(&parsed_source)?;
}
Expand Down Expand Up @@ -418,7 +419,7 @@ impl deno_graph::source::Resolver for JsrResolver {
&self,
specifier_text: &str,
referrer_range: &deno_graph::Range,
_mode: deno_graph::source::ResolutionMode,
_kind: deno_graph::source::ResolutionKind,
) -> Result<ModuleSpecifier, deno_graph::source::ResolveError> {
if let Ok(package_ref) = JsrPackageReqReference::from_str(specifier_text) {
if self.member.name == package_ref.req().name
Expand Down Expand Up @@ -454,7 +455,7 @@ struct SyncLoader<'a> {
files: &'a HashMap<PackagePath, Vec<u8>>,
}

impl<'a> SyncLoader<'a> {
impl SyncLoader<'_> {
fn load_sync(
&self,
specifier: &ModuleSpecifier,
Expand Down Expand Up @@ -484,7 +485,7 @@ impl<'a> SyncLoader<'a> {
}
}

impl<'a> deno_graph::source::Loader for SyncLoader<'a> {
impl deno_graph::source::Loader for SyncLoader<'_> {
fn load(
&self,
specifier: &ModuleSpecifier,
Expand Down Expand Up @@ -628,7 +629,7 @@ struct GcsLoader<'a> {
version: &'a Version,
}

impl<'a> GcsLoader<'a> {
impl GcsLoader<'_> {
fn load_inner(
&self,
specifier: &ModuleSpecifier,
Expand Down Expand Up @@ -669,7 +670,7 @@ impl<'a> GcsLoader<'a> {
}
}

impl<'a> deno_graph::source::Loader for GcsLoader<'a> {
impl deno_graph::source::Loader for GcsLoader<'_> {
fn load(
&self,
specifier: &ModuleSpecifier,
Expand Down Expand Up @@ -802,6 +803,21 @@ fn collect_dependencies(
Ok(dependencies)
}

fn check_for_banned_extensions(
parsed_source: &ParsedSource,
) -> Result<(), PublishError> {
match parsed_source.media_type() {
deno_ast::MediaType::Cjs | deno_ast::MediaType::Cts => {
Err(PublishError::CommonJs {
specifier: parsed_source.specifier().to_string(),
line: 0,
column: 0,
})
}
_ => Ok(()),
}
}

fn check_for_banned_syntax(
parsed_source: &ParsedSource,
) -> Result<(), PublishError> {
Expand Down Expand Up @@ -957,8 +973,15 @@ fn check_for_banned_triple_slash_directives(
#[cfg(test)]
mod tests {
fn parse(source: &str) -> deno_ast::ParsedSource {
let specifier = deno_ast::ModuleSpecifier::parse("file:///mod.ts").unwrap();
let media_type = deno_ast::MediaType::TypeScript;
parse_with_media_type(source, media_type)
}

fn parse_with_media_type(
source: &str,
media_type: deno_ast::MediaType,
) -> deno_ast::ParsedSource {
let specifier = deno_ast::ModuleSpecifier::parse("file:///mod.ts").unwrap();
deno_ast::parse_module(deno_ast::ParseParams {
specifier,
text: source.into(),
Expand All @@ -970,6 +993,27 @@ mod tests {
.unwrap()
}

#[test]
fn banned_extensions() {
let x =
parse_with_media_type("let x = 1;", deno_ast::MediaType::TypeScript);
assert!(super::check_for_banned_extensions(&x).is_ok());

let x = parse_with_media_type("let x = 1;", deno_ast::MediaType::Cjs);
let err = super::check_for_banned_extensions(&x).unwrap_err();
assert!(
matches!(err, super::PublishError::CommonJs { .. }),
"{err:?}",
);

let x = parse_with_media_type("let x = 1;", deno_ast::MediaType::Cts);
let err = super::check_for_banned_extensions(&x).unwrap_err();
assert!(
matches!(err, super::PublishError::CommonJs { .. }),
"{err:?}",
);
}

#[test]
fn banned_triple_slash_directives() {
let x = parse("let x = 1;");
Expand Down
10 changes: 5 additions & 5 deletions api/src/api/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub async fn update_user(mut req: Request<Body>) -> ApiResult<ApiFullUser> {
iam.check_admin_access()?;

let user_id = req.param_uuid("user_id")?;
Span::current().record("user_id", &field::display(&user_id));
Span::current().record("user_id", field::display(&user_id));
let ApiAdminUpdateUserRequest {
is_staff,
is_blocked,
Expand Down Expand Up @@ -172,7 +172,7 @@ pub async fn patch_scopes(mut req: Request<Body>) -> ApiResult<ApiFullScope> {
iam.check_admin_access()?;

let scope = req.param_scope()?;
Span::current().record("scope", &field::display(&scope));
Span::current().record("scope", field::display(&scope));

let ApiAdminUpdateScopeRequest {
package_limit,
Expand Down Expand Up @@ -214,8 +214,8 @@ pub async fn assign_scope(mut req: Request<Body>) -> ApiResult<ApiScope> {
iam.check_admin_access()?;

let ApiAssignScopeRequest { scope, user_id } = decode_json(&mut req).await?;
Span::current().record("scope", &field::display(&scope));
Span::current().record("user_id", &field::display(&user_id));
Span::current().record("scope", field::display(&scope));
Span::current().record("user_id", field::display(&user_id));

let db = req.data::<Database>().unwrap();

Expand Down Expand Up @@ -268,7 +268,7 @@ pub async fn requeue_publishing_tasks(req: Request<Body>) -> ApiResult<()> {

let publishing_task_id = req.param_uuid("publishing_task")?;
Span::current()
.record("publishing_task", &field::display(&publishing_task_id));
.record("publishing_task", field::display(&publishing_task_id));

let db = req.data::<Database>().unwrap().clone();
let task = db
Expand Down
8 changes: 4 additions & 4 deletions api/src/api/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ mod tests {

async fn details(t: &mut TestSetup, code: &str) -> Response<Body> {
t.http()
.get(&format!("/api/authorizations/details/{}", code))
.get(format!("/api/authorizations/details/{}", code))
.call()
.await
.unwrap()
Expand Down Expand Up @@ -335,7 +335,7 @@ mod tests {

let mut resp = t
.http()
.post(&format!("/api/authorizations/approve/{}", auth.code))
.post(format!("/api/authorizations/approve/{}", auth.code))
.call()
.await
.unwrap();
Expand Down Expand Up @@ -399,7 +399,7 @@ mod tests {

let mut resp = t
.http()
.post(&format!("/api/authorizations/approve/{}", auth.code))
.post(format!("/api/authorizations/approve/{}", auth.code))
.call()
.await
.unwrap();
Expand Down Expand Up @@ -454,7 +454,7 @@ mod tests {

let mut resp = t
.http()
.post(&format!("/api/authorizations/deny/{}", auth.code))
.post(format!("/api/authorizations/deny/{}", auth.code))
.call()
.await
.unwrap();
Expand Down
Loading

0 comments on commit 08d8154

Please sign in to comment.