Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: CI
on: push
jobs:
test:
name: CI
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Run tests
run: deno test --allow-env --allow-read=. --allow-net=api.github.com
7 changes: 7 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"imports": {
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
"preact-render-to-string": "https://esm.sh/*[email protected]"
}
}
24 changes: 24 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"**/*-lock.json"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.68.0.wasm",
"https://plugins.dprint.dev/json-0.15.1.wasm",
"https://plugins.dprint.dev/markdown-0.13.1.wasm",
"https://plugins.dprint.dev/prettier-0.7.0.json@4e846f43b32981258cef5095b3d732522947592e090ef52333801f9d6e8adb33"
"https://plugins.dprint.dev/typescript-0.85.0.wasm",
"https://plugins.dprint.dev/json-0.17.4.wasm",
"https://plugins.dprint.dev/markdown-0.15.3.wasm",
"https://plugins.dprint.dev/prettier-0.26.1.json@fdbe31f6aecd24f9d6b924214710a6766050d03146163b4e241e6056b2462f2e"
]
}
9 changes: 9 additions & 0 deletions handleRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@ Deno.test("tryResolvePluginUrl", async () => {
);
});

Deno.test("should redirect when the url has an @ sign in it", async () => {
assertEquals(
await getRedirectUrl(
"https://plugins.dprint.dev/prettier-0.24.0.json@9a57d0d8e440ad90d07a503166af47e7a6a886abd46767933f9c279f72468596",
),
"https://plugins.dprint.dev/prettier-0.24.0.json",
);
});

// todo: mock github api for these tests

Deno.test("tryResolveSchemaUrl", async () => {
Expand Down
14 changes: 14 additions & 0 deletions handleRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ const contentTypes = {

export async function handleRequest(request: Request) {
const url = new URL(request.url);
const atSignIndex = url.pathname.lastIndexOf("@");
if (atSignIndex >= 0 && url.pathname.length - atSignIndex === 65) {
return redirectWithoutHash(url, atSignIndex);
}
if (url.pathname.includes("testing-this-out")) {
return new Response((Deno.env.get("DPRINT_PLUGINS_GH_TOKEN")?.length ?? 0).toString(), {
status: 200,
});
}
const newUrl = await resolvePluginOrSchemaUrl(url);
if (newUrl != null) {
const contentType = newUrl.endsWith(".json")
Expand Down Expand Up @@ -161,3 +170,8 @@ function create404Response() {
statusText: "Not Found",
});
}

function redirectWithoutHash(url: URL, atSignIndex: number) {
const newUrl = new URL(url.pathname.slice(0, atSignIndex), url);
return createRedirectResponse(newUrl.toString());
}
4 changes: 2 additions & 2 deletions home.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @jsx h */
import { h } from "https://x.lcas.dev/preact@10.5.12/mod.js";
import { renderToString } from "https://x.lcas.dev/preact@10.5.12/ssr.js";
import { h } from "preact";
import { renderToString } from "preact-render-to-string";
import { PluginData, PluginsData, readInfoFile } from "./readInfoFile.ts";

export async function renderHome() {
Expand Down
8 changes: 4 additions & 4 deletions plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export async function tryResolveLatestJson(url: URL) {
if (!result) {
return undefined;
}
const username = result.pathname.groups[0];
const shortRepoName = result.pathname.groups[1];
const username = result.pathname.groups[0]!;
const shortRepoName = result.pathname.groups[1]!;
const latestInfo = await getLatestInfo(username, shortRepoName);
if (latestInfo == null) {
return 404;
Expand Down Expand Up @@ -104,8 +104,8 @@ async function userRepoTagPatternMapper(
) {
const result = pattern.exec(url);
if (result) {
const username = result.pathname.groups[0];
const repo = await getFullRepoName(username, result.pathname.groups[1]);
const username = result.pathname.groups[0]!;
const repo = await getFullRepoName(username, result.pathname.groups[1]!);
const tag = result.pathname.groups[2];
if (tag === "latest") {
return `https://github.com/${username}/${repo}/releases/latest/download/${fileName}`;
Expand Down