From e739364a4071522013b8d020eeaaf289008fce53 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Mon, 28 Oct 2024 12:55:09 +0700 Subject: [PATCH 1/3] feat: add devtools updates --- .../routes/devtools/updates.json/+server.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 apps/svelte.dev/src/routes/devtools/updates.json/+server.ts diff --git a/apps/svelte.dev/src/routes/devtools/updates.json/+server.ts b/apps/svelte.dev/src/routes/devtools/updates.json/+server.ts new file mode 100644 index 0000000000..4793603c9d --- /dev/null +++ b/apps/svelte.dev/src/routes/devtools/updates.json/+server.ts @@ -0,0 +1,30 @@ +import { json } from '@sveltejs/kit'; + +export const prerender = true; + +export async function GET({ fetch }) { + const gh: Array<{ name: string }> = await fetch( + 'https://api.github.com/repos/sveltejs/svelte-devtools/tags' + ).then((r) => r.json()); + + // v2.2.0 is the first version that has the Firefox extension + const tags = gh.reverse().slice(gh.findIndex((t) => t.name === 'v2.2.0')); + const base = 'https://github.com/sveltejs/svelte-devtools/releases/download'; + return json({ + addons: { + 'firefox-devtools@svelte.dev': { + updates: tags.map(({ name: tag }) => { + return { + version: tag, + update_link: `${base}/${tag}/svelte-devtools.xpi`, + applications: requirements[tag] && { gecko: requirements[tag] } + }; + }) + } + } + }); +} + +const requirements: Record = { + 'v2.2.2': { strict_min_version: '121.0' } +}; From b6f36f3f97ec74e6c4201c255883724df69d92fd Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Mon, 28 Oct 2024 15:17:46 +0700 Subject: [PATCH 2/3] add comment to explain the server route --- apps/svelte.dev/src/routes/devtools/updates.json/+server.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/svelte.dev/src/routes/devtools/updates.json/+server.ts b/apps/svelte.dev/src/routes/devtools/updates.json/+server.ts index 4793603c9d..b89de15902 100644 --- a/apps/svelte.dev/src/routes/devtools/updates.json/+server.ts +++ b/apps/svelte.dev/src/routes/devtools/updates.json/+server.ts @@ -1,3 +1,7 @@ +// We manage FF extension by ourselves through GH releases and this acts as `update_url` +// for our users to automatically update their extension when a new version is released +// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_specific_settings#update_url + import { json } from '@sveltejs/kit'; export const prerender = true; From cc47fb1a4bb8ed6f5bcf9f115fe1184276937cf0 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 28 Oct 2024 14:35:38 -0400 Subject: [PATCH 3/3] make it an ISR route, handle errors --- .../routes/devtools/updates.json/+server.ts | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/svelte.dev/src/routes/devtools/updates.json/+server.ts b/apps/svelte.dev/src/routes/devtools/updates.json/+server.ts index b89de15902..a07b62ea7a 100644 --- a/apps/svelte.dev/src/routes/devtools/updates.json/+server.ts +++ b/apps/svelte.dev/src/routes/devtools/updates.json/+server.ts @@ -1,15 +1,23 @@ +import { error, json } from '@sveltejs/kit'; +import type { ServerlessConfig } from '@sveltejs/adapter-vercel'; + +export const config: ServerlessConfig = { + isr: { + expiration: 300 + } +}; + // We manage FF extension by ourselves through GH releases and this acts as `update_url` // for our users to automatically update their extension when a new version is released // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_specific_settings#update_url +export async function GET({ fetch }) { + const response = await fetch('https://api.github.com/repos/sveltejs/svelte-devtools/tags'); -import { json } from '@sveltejs/kit'; - -export const prerender = true; + if (!response.ok) { + error(response.status); + } -export async function GET({ fetch }) { - const gh: Array<{ name: string }> = await fetch( - 'https://api.github.com/repos/sveltejs/svelte-devtools/tags' - ).then((r) => r.json()); + const gh: Array<{ name: string }> = await response.json(); // v2.2.0 is the first version that has the Firefox extension const tags = gh.reverse().slice(gh.findIndex((t) => t.name === 'v2.2.0'));