From b560336d342f630fdb146024322f1ee4bc1d9a12 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Wed, 7 Feb 2024 07:32:48 +0100 Subject: [PATCH] chore: prevent jsr modules to be published (#341) --- 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..83b7ad2 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) as Record; + 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,