From cfb5e586fe8cadce4e55cae3c3a3e16f271581bf Mon Sep 17 00:00:00 2001 From: crowlkats Date: Tue, 6 Feb 2024 23:24:52 +0100 Subject: [PATCH 1/3] chore: prevent jsr modules to be published --- api/async/publish.ts | 22 ++++++++++++++++++++++ deps.ts | 1 + 2 files changed, 23 insertions(+) diff --git a/api/async/publish.ts b/api/async/publish.ts index 1501fd3..9a4b3f0 100644 --- a/api/async/publish.ts +++ b/api/async/publish.ts @@ -12,6 +12,7 @@ import { Context, join, + jsoncParse, pooledMap, readAll, SQSEvent, @@ -159,6 +160,27 @@ async function publishGithub(build: NewBuild) { // If this is a file in the .git folder, ignore it if (filename.startsWith("/.git/") || filename === "/.git") return; + if (filename === "deno.json" || filename === "deno.jsonc") { + const file = await Deno.open(join(path, entry.path)); + const body = await readAll(file); + const bodyText = new TextDecoder().decode(body); + try { + const bodyJSON = jsoncParse(bodyText); + if ("name" in bodyJSON) { + throw new TypeError( + "This module is meant for JSR publishing, and as such cannot be published to /x/", + ); + } + } catch (e) { + if ( + e.message === + "This module is meant for JSR publishing, and as such cannot be published to /x/" + ) { + throw e; + } + } + } + if (entry.isFile) { const stat = await Deno.stat(entry.path); directory.push({ path: filename, size: stat.size, type: "file" }); diff --git a/deps.ts b/deps.ts index 4759d21..549c829 100644 --- a/deps.ts +++ b/deps.ts @@ -1,6 +1,7 @@ // Copyright 2020-2021 the Deno authors. All rights reserved. MIT license. export { expandGlob, walk } from "https://deno.land/std@0.149.0/fs/mod.ts"; +export { parse as jsoncParse } from "https://deno.land/std@0.214.0/jsonc/mod.ts"; export { join } from "https://deno.land/std@0.149.0/path/mod.ts"; export type { APIGatewayProxyEventV2, From 27d553ae74863b268c47c754cb70299bc3abece0 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 7 Feb 2024 07:22:12 +0100 Subject: [PATCH 2/3] fix --- api/async/publish.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/async/publish.ts b/api/async/publish.ts index 9a4b3f0..9c48436 100644 --- a/api/async/publish.ts +++ b/api/async/publish.ts @@ -165,7 +165,7 @@ async function publishGithub(build: NewBuild) { const body = await readAll(file); const bodyText = new TextDecoder().decode(body); try { - const bodyJSON = jsoncParse(bodyText); + const bodyJSON: Record = jsoncParse(bodyText); if ("name" in bodyJSON) { throw new TypeError( "This module is meant for JSR publishing, and as such cannot be published to /x/", From ae41f6404fee4d743d9000a8b547d81b34b0d026 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 7 Feb 2024 07:29:23 +0100 Subject: [PATCH 3/3] fix --- api/async/publish.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/async/publish.ts b/api/async/publish.ts index 9c48436..83b7ad2 100644 --- a/api/async/publish.ts +++ b/api/async/publish.ts @@ -165,7 +165,7 @@ async function publishGithub(build: NewBuild) { const body = await readAll(file); const bodyText = new TextDecoder().decode(body); try { - const bodyJSON: Record = jsoncParse(bodyText); + const bodyJSON = jsoncParse(bodyText) as Record; if ("name" in bodyJSON) { throw new TypeError( "This module is meant for JSR publishing, and as such cannot be published to /x/",