Skip to content

Commit

Permalink
chore: prevent jsr modules to be published (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Feb 7, 2024
1 parent 3edce11 commit b560336
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions api/async/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import {
Context,
join,
jsoncParse,
pooledMap,
readAll,
SQSEvent,
Expand Down Expand Up @@ -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<string, unknown>;
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" });
Expand Down
1 change: 1 addition & 0 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit b560336

Please sign in to comment.