Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prevent jsr modules to be published #341

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
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/[email protected]/fs/mod.ts";
export { parse as jsoncParse } from "https://deno.land/[email protected]/jsonc/mod.ts";
export { join } from "https://deno.land/[email protected]/path/mod.ts";
export type {
APIGatewayProxyEventV2,
Expand Down
Loading