From 2ce1e0c4e5a04d0534f7ed38e7a611c8bbcb8750 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Thu, 24 Sep 2026 09:53:32 -0500 Subject: [PATCH 01/11] feat: accept npm plugins only when they are ESM only green-tea is ESM end to end and its Node floor is moving up; a CJS or dual package brings a require path that is the first thing to break. The check lives in readEntry, so it bites on CI with every other registry check, and validate.mjs inherits it when it is written. Signed-off-by: Diego Resendez --- package.json | 2 +- scripts/registry.mjs | 42 +++++++++++++++++++++++++++++++++++++-- scripts/registry.test.mjs | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 scripts/registry.test.mjs diff --git a/package.json b/package.json index bd120ac..c542f51 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "dev": "astro dev", "build": "astro build", "preview": "astro preview", - "test": "node scripts/deploy.mjs --self-test", + "test": "node scripts/deploy.mjs --self-test && node --test scripts/registry.test.mjs", "deploy": "npm run build && node scripts/deploy.mjs", "astro": "astro" }, diff --git a/scripts/registry.mjs b/scripts/registry.mjs index 0c4e6ce..c0dce67 100644 --- a/scripts/registry.mjs +++ b/scripts/registry.mjs @@ -48,7 +48,36 @@ function compare(a, b) { * `@green-tea/core`, which has two published versions and `"latest": null`. */ export function newestVersion(versions) { - return [...versions].sort(compare).pop(); + return byNewest(versions)[0]; +} + +/** Versions sorted newest first. */ +export function byNewest(versions) { + return [...versions].sort(compare).reverse(); +} + +/** + * ESM only, with no CJS way in at all — dual packages included, because green-tea is ESM end to + * end and a `require` path is what breaks first when the Node floor moves. + */ +export function isEsmOnly({ type, main, exports }) { + if (type !== 'module') return false; + const cjs = (node, key) => { + if (key === 'require') return true; + if (typeof node === 'string') return node.endsWith('.cjs'); + if (node && typeof node === 'object') return Object.entries(node).some(([k, v]) => cjs(v, k)); + + return false; + }; + + return !cjs(main) && !cjs(exports); +} + +/** npm stores this literal string when a package ships no README. */ +export function npmReadme(packument) { + const readme = packument.readme ?? ''; + + return readme.startsWith('ERROR: No README data found') ? '' : readme; } async function getJson(url, what) { @@ -76,6 +105,10 @@ export async function readNpm(name) { devDependencies: version.devDependencies ?? {}, dependencies: version.dependencies ?? {}, peerDependencies: version.peerDependencies ?? {}, + type: version.type, + main: version.main, + exports: version.exports, + readme: npmReadme(packument), }; } @@ -118,6 +151,11 @@ export function declaredRuntimes({ engines, runtimeCompat }) { export async function readEntry(entry) { try { const npm = entry.npm ? await readNpm(entry.npm) : undefined; + if (npm && !isEsmOnly(npm)) { + throw new Error( + `npm ${entry.npm}@${npm.newest} is not ESM only (type: ${npm.type ?? 'unset'}, main: ${npm.main ?? '-'}, exports: ${JSON.stringify(npm.exports ?? null)})`, + ); + } const jsr = entry.jsr ? await readJsr(entry.jsr) : undefined; return { @@ -129,7 +167,7 @@ export async function readEntry(entry) { }; } catch (error) { if (STRICT) throw error; - console.warn(` left out, registry did not answer: ${entry.jsr ?? entry.npm} (${error.message})`); + console.warn(` left out: ${entry.jsr ?? entry.npm} (${error.message})`); return null; } diff --git a/scripts/registry.test.mjs b/scripts/registry.test.mjs new file mode 100644 index 0000000..c362804 --- /dev/null +++ b/scripts/registry.test.mjs @@ -0,0 +1,38 @@ +// Pure pieces of the registry reader. Network calls are not tested here; `CI=true npm run build` +// exercises them against the live registries. +import { test } from 'node:test'; +import assert from 'node:assert/strict'; + +import { isEsmOnly, byNewest, npmReadme } from './registry.mjs'; + +test('isEsmOnly: type module with ESM exports passes', () => { + assert.equal(isEsmOnly({ type: 'module', exports: { '.': { import: './dist/index.js', types: './dist/index.d.ts' } } }), true); +}); + +test('isEsmOnly: no type module is CJS', () => { + assert.equal(isEsmOnly({ main: './index.js' }), false); +}); + +test('isEsmOnly: dual package is rejected', () => { + assert.equal(isEsmOnly({ type: 'module', exports: { '.': { import: './index.js', require: './index.cjs' } } }), false); +}); + +test('isEsmOnly: a .cjs anywhere in exports or main is rejected', () => { + assert.equal(isEsmOnly({ type: 'module', exports: { './legacy': './legacy.cjs' } }), false); + assert.equal(isEsmOnly({ type: 'module', main: './index.cjs' }), false); +}); + +test('byNewest: releases outrank their prereleases, betas order numerically', () => { + assert.deepEqual(byNewest(['26.9.0-beta.2', '26.9.0', '26.9.0-beta.10', '26.8.1']), [ + '26.9.0', + '26.9.0-beta.10', + '26.9.0-beta.2', + '26.8.1', + ]); +}); + +test('npmReadme: npm placeholder means no README', () => { + assert.equal(npmReadme({ readme: 'ERROR: No README data found!' }), ''); + assert.equal(npmReadme({}), ''); + assert.equal(npmReadme({ readme: '# hi' }), '# hi'); +}); -- 2.54.1 From d61b577a488abb120888cf47a437e4968c172449 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Thu, 24 Sep 2026 09:54:11 -0500 Subject: [PATCH 02/11] feat: clean plugin READMEs before they reach the page A README is third-party HTML that can change after review. It is sanitized against a closed allowlist on every build, and its relative links are pointed at the published version so images and docs resolve without knowing the author's branch. Signed-off-by: Diego Resendez --- package-lock.json | 173 +++++++++++++++++++++++++++++++++++++- package.json | 3 +- scripts/readme.mjs | 46 ++++++++++ scripts/registry.test.mjs | 41 +++++++++ 4 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 scripts/readme.mjs diff --git a/package-lock.json b/package-lock.json index 056d767..39d1eac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "26.9.0", "dependencies": { "@astrojs/sitemap": "^3.7.3", - "astro": "^7.1.6" + "astro": "^7.1.6", + "sanitize-html": "^2.17.7" }, "engines": { "node": ">=22.12.0" @@ -2298,6 +2299,21 @@ "integrity": "sha512-aylIc7Z9y4yzHYAJNuESG3hfhC+0Ibp/MAMiaOZgNv4pmEdFyfZhhhny4MNiAfWdBQ1RQ2mfDWmM1x8SvGyp8g==", "license": "CC0-1.0" }, + "node_modules/dayjs": { + "version": "1.11.23", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.23.tgz", + "integrity": "sha512-QDTCU0M0MxR3hQfnlDJfwekQiaanm1ubOD231u73WBckQ/fsamwRLiE2GBz6D3a/xF1NgfiDLJjXBa1hYOYTtQ==", + "license": "MIT" + }, + "node_modules/deepmerge": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz", + "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/defu": { "version": "6.1.7", "resolved": "https://registry.npmjs.org/defu/-/defu-6.1.7.tgz", @@ -2479,6 +2495,18 @@ "@esbuild/win32-x64": "0.28.2" } }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/eventemitter3": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.4.tgz", @@ -2675,6 +2703,107 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/htmlparser2": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-12.0.0.tgz", + "integrity": "sha512-Tz7u1i95/g2x2jz81+x0FBVhBhY5aRTvD3tXXdFaljuNdzDLJ8UGNRrTcj2cgQvAg3iW/h77Fz15nLW0L0CrZw==", + "funding": [ + "https://github.com/fb55/htmlparser2?sponsor=1", + { + "type": "github", + "url": "https://github.com/sponsors/fb55" + } + ], + "license": "MIT", + "dependencies": { + "domelementtype": "^3.0.0", + "domhandler": "^6.0.0", + "domutils": "^4.0.2", + "entities": "^8.0.0" + }, + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/htmlparser2/node_modules/dom-serializer": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-3.1.1.tgz", + "integrity": "sha512-4MEa38/QexBob6gFNwu+EGdWvhJ1OKuNwdYY3Y3NyeWDQfnGeDYQUDfIRzWu5B5gsv03so2Uxd28YC6zrsx3Lw==", + "license": "MIT", + "dependencies": { + "domelementtype": "^3.0.0", + "domhandler": "^6.0.0", + "entities": "^8.0.0" + }, + "engines": { + "node": ">=20.19.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" + } + }, + "node_modules/htmlparser2/node_modules/domelementtype": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-3.0.0.tgz", + "integrity": "sha512-umCQid3jKbDmVjx8jGaW7uUykm4DEUeyV21hPxNMo2nV955DhUThwqyOIDtreepP31hl84X7G5U9ZfsWvIB3Pg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fb55" + } + ], + "license": "BSD-2-Clause", + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/htmlparser2/node_modules/domhandler": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-6.0.1.tgz", + "integrity": "sha512-gYzvtM72ZtxQO0T048kd6HWSbbGCNOUwcnfQ01cqIJ4X2IYKFFHZ5mKvrQETcFXxsRObZulDaKmy//R7TPtsBg==", + "license": "BSD-2-Clause", + "dependencies": { + "domelementtype": "^3.0.0" + }, + "engines": { + "node": ">=20.19.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/fb55/domhandler?sponsor=1" + } + }, + "node_modules/htmlparser2/node_modules/domutils": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-4.0.2.tgz", + "integrity": "sha512-qI4JLRKnSzqFqr7hAlS5xQDusBCjKSEG4t4+7aNrIQMHBcsC2TGEhuyABJdYkgSewL57PNLYEiibY2iPKhKpaA==", + "license": "BSD-2-Clause", + "dependencies": { + "dom-serializer": "^3.0.0", + "domelementtype": "^3.0.0", + "domhandler": "^6.0.0" + }, + "engines": { + "node": ">=20.19.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/fb55/domutils?sponsor=1" + } + }, + "node_modules/htmlparser2/node_modules/entities": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-8.1.0.tgz", + "integrity": "sha512-kxL7msIffSuh9aaFAMD7rxAIuTRMAHMeBtgHW2yUdWw732ZNh4MehkF2gdjvtdmikkaIP9bFDDJOPlsvm7avrA==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=20.19.0" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/http-cache-semantics": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.2.0.tgz", @@ -2717,6 +2846,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/is-plain-object": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.1.0.tgz", + "integrity": "sha512-bUi/yjmtKYcRVUtWRGr0UA6xEFh2I6zWUwMrUXB3s7bmYCaZ8a+0ZsTRkrawh/mzlSD1Y0Ph8bp/U+TvBpWDNw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/js-yaml": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.2.tgz", @@ -2745,6 +2883,15 @@ "integrity": "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==", "license": "MIT" }, + "node_modules/launder": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/launder/-/launder-1.7.1.tgz", + "integrity": "sha512-mU6WRz5EusL9ZZuiZ5SO4Y6C0P9PAUR9iwdb6bzj4KDihm28DiHFw+/yk9DBH4f+Pv1wuzQ4e2jV3oQ7mkIqvw==", + "license": "MIT", + "dependencies": { + "dayjs": "^1.11.7" + } + }, "node_modules/lightningcss": { "version": "1.33.0", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", @@ -3317,6 +3464,12 @@ "integrity": "sha512-yQA4H19AmPEoMUeavPMDIe1higySl/gH/yaQrkT/s07Qp+7pp2hYz30N3z2l5BkjVkF9Ow6o0wjJamm2y7Sn0A==", "license": "MIT" }, + "node_modules/parse-srcset": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/parse-srcset/-/parse-srcset-1.0.2.tgz", + "integrity": "sha512-/2qh0lav6CmI15FzA3i/2Bzk2zCgQhGMkvhOhKNcBVQ1ldgpbfiNTVslmooUmWJcADi1f1kIeynbDRVzNlfR6Q==", + "license": "MIT" + }, "node_modules/piccolore": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/piccolore/-/piccolore-0.1.3.tgz", @@ -3497,6 +3650,24 @@ "@rolldown/binding-win32-x64-msvc": "1.2.9" } }, + "node_modules/sanitize-html": { + "version": "2.17.7", + "resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-2.17.7.tgz", + "integrity": "sha512-PGtEkc9cbnedU3s9TmzDbpsZ8w086g/0Q8k8/oIO1NLNU3i5k9yn835CrjJSajp1KMmkisbO1qPXxNKO3welAg==", + "license": "MIT", + "dependencies": { + "deepmerge": "^4.2.2", + "escape-string-regexp": "^4.0.0", + "htmlparser2": "^12.0.0", + "is-plain-object": "^5.0.0", + "launder": "^1.7.1", + "parse-srcset": "^1.0.2", + "postcss": "^8.3.11" + }, + "engines": { + "node": ">=22.12.0" + } + }, "node_modules/satteri": { "version": "0.10.5", "resolved": "https://registry.npmjs.org/satteri/-/satteri-0.10.5.tgz", diff --git a/package.json b/package.json index c542f51..35b5a8b 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ }, "dependencies": { "@astrojs/sitemap": "^3.7.3", - "astro": "^7.1.6" + "astro": "^7.1.6", + "sanitize-html": "^2.17.7" } } diff --git a/scripts/readme.mjs b/scripts/readme.mjs new file mode 100644 index 0000000..213ec23 --- /dev/null +++ b/scripts/readme.mjs @@ -0,0 +1,46 @@ +// A plugin's README is somebody else's HTML. Review reads the yaml once; the README can change on +// any later publish and reach the site at the next Friday cut. So it is cleaned against a closed +// allowlist every build, and never trusted because the entry was. +import sanitizeHtml from 'sanitize-html'; + +const HEX = /^#[0-9a-f]{3,8}$/i; + +/** Relative URLs resolve against the published package; anchors and absolute URLs stay. */ +function absolute(url, base) { + if (!url || url.startsWith('#')) return url; + try { + return new URL(url, base).href; + } catch { + return url; + } +} + +/** Only touch the attribute when it is there — setting it to `undefined` renders a bare `href`. */ +function rebase(attribs, key, base) { + return key in attribs ? { ...attribs, [key]: absolute(attribs[key], base) } : attribs; +} + +export function cleanReadme(html, base) { + return sanitizeHtml(html, { + allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'h1', 'h2', 'details', 'summary', 'picture', 'source']), + allowedAttributes: { + '*': ['id', 'align'], + a: ['href', 'title'], + img: ['src', 'alt', 'title', 'width', 'height'], + source: ['srcset', 'media'], + pre: ['class', 'style', 'tabindex', 'data-language'], + span: ['class', 'style'], + code: ['class'], + }, + // Only what shiki writes. Anything else (position, inset, z-index…) would let a README draw + // over the page around it. + allowedStyles: { + '*': { color: [HEX], 'background-color': [HEX], 'overflow-x': [/^auto$/] }, + }, + allowedSchemes: ['http', 'https', 'mailto'], + transformTags: { + a: (tagName, attribs) => ({ tagName, attribs: rebase(attribs, 'href', base) }), + img: (tagName, attribs) => ({ tagName, attribs: rebase(attribs, 'src', base) }), + }, + }); +} diff --git a/scripts/registry.test.mjs b/scripts/registry.test.mjs index c362804..8400caa 100644 --- a/scripts/registry.test.mjs +++ b/scripts/registry.test.mjs @@ -4,6 +4,7 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; import { isEsmOnly, byNewest, npmReadme } from './registry.mjs'; +import { cleanReadme } from './readme.mjs'; test('isEsmOnly: type module with ESM exports passes', () => { assert.equal(isEsmOnly({ type: 'module', exports: { '.': { import: './dist/index.js', types: './dist/index.d.ts' } } }), true); @@ -36,3 +37,43 @@ test('npmReadme: npm placeholder means no README', () => { assert.equal(npmReadme({}), ''); assert.equal(npmReadme({ readme: '# hi' }), '# hi'); }); + +const BASE = 'https://jsr.io/@green-tea/jwt/26.9.0-beta.0/'; + +test('cleanReadme: strips scripts, handlers and javascript: links', () => { + const html = cleanReadme('a', BASE); + assert.doesNotMatch(html, /script|onerror|javascript:/); +}); + +test('cleanReadme: keeps align and width (our READMEs center the logo)', () => { + const html = cleanReadme('

l

', BASE); + assert.match(html, /

/); + assert.match(html, /width="96"/); +}); + +test('cleanReadme: relative links and images point at the published version', () => { + const html = cleanReadme('a', BASE); + assert.match(html, /href="https:\/\/jsr\.io\/@green-tea\/jwt\/26\.9\.0-beta\.0\/docs\/a\.md"/); + assert.match(html, /src="https:\/\/jsr\.io\/@green-tea\/jwt\/26\.9\.0-beta\.0\/assets\/l\.png"/); + const npm = cleanReadme('', 'https://cdn.jsdelivr.net/npm/green-tea-foo@1.0.0/'); + assert.match(npm, /src="https:\/\/cdn\.jsdelivr\.net\/npm\/green-tea-foo@1\.0\.0\/l\.png"/); +}); + +test('cleanReadme: leaves anchors alone', () => { + assert.match(cleanReadme('i', BASE), /href="#install"/); +}); + +test('cleanReadme: styles — shiki colours stay, layout tricks go', () => { + const html = cleanReadme( + '

x
y
', + BASE, + ); + assert.match(html, /color:#F97583/); + assert.match(html, /background-color:#24292e/); + assert.doesNotMatch(html, /position|inset/); +}); + +test('cleanReadme: an without href does not become a link', () => { + const html = cleanReadme('tn', BASE); + assert.doesNotMatch(html, /href|src/); +}); -- 2.54.1 From 84dae62864cf902d17c0142a7f2cdc524f35ad13 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Thu, 24 Sep 2026 09:54:51 -0500 Subject: [PATCH 03/11] feat: read entries, registry data and READMEs in one loader renderMarkdown only exists inside a content loader, and the README should render through the site's own pipeline. One loader also means the home and every plugin page share a single registry read per build. Signed-off-by: Diego Resendez --- package-lock.json | 1 + package.json | 1 + scripts/loader.mjs | 43 +++++++++++++++++++++++++++++++++++++++++++ scripts/registry.mjs | 31 +++++++++++++++++++++++++++---- src/content.config.ts | 40 +++++++++++++++++++++++++--------------- src/pages/index.astro | 43 ++++++++++++++++--------------------------- 6 files changed, 113 insertions(+), 46 deletions(-) create mode 100644 scripts/loader.mjs diff --git a/package-lock.json b/package-lock.json index 39d1eac..f80757d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@astrojs/sitemap": "^3.7.3", "astro": "^7.1.6", + "js-yaml": "^4.3.2", "sanitize-html": "^2.17.7" }, "engines": { diff --git a/package.json b/package.json index 35b5a8b..9ae2a6a 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "dependencies": { "@astrojs/sitemap": "^3.7.3", "astro": "^7.1.6", + "js-yaml": "^4.3.2", "sanitize-html": "^2.17.7" } } diff --git a/scripts/loader.mjs b/scripts/loader.mjs new file mode 100644 index 0000000..821c616 --- /dev/null +++ b/scripts/loader.mjs @@ -0,0 +1,43 @@ +// The `plugins` collection's loader. It replaces `glob` because `renderMarkdown` only exists inside +// a loader, and the README has to be rendered with the site's own pipeline (shiki included). +// Wrapping `glob` was tried on 2026-09-24 and the added fields did not persist; a standalone +// loader did. +import { readdirSync, readFileSync } from 'node:fs'; +import yaml from 'js-yaml'; + +import { readEntry } from './registry.mjs'; +import { cleanReadme } from './readme.mjs'; + +/** `entrySchema` validates one yaml file; it is the contributor-facing contract. */ +export function pluginsLoader(entrySchema) { + return { + name: 'plugins', + // ponytail: no file watcher — after editing a yaml in `npm run dev`, restart it. Add a watcher + // if contributors start previewing entries locally. + load: async ({ store, renderMarkdown, config }) => { + store.clear(); + const dir = new URL('src/content/plugins/', config.root); + const files = readdirSync(dir).filter((file) => file.endsWith('.yaml') && !file.startsWith('_')); + + await Promise.all( + files.map(async (file) => { + const parsed = entrySchema.safeParse(yaml.load(readFileSync(new URL(file, dir), 'utf8'))); + if (!parsed.success) { + throw new Error(`src/content/plugins/${file}: ${parsed.error.issues.map((i) => i.message).join('; ')}`); + } + + const live = await readEntry(parsed.data); + if (!live) return; + + const { readme, readmeBase, ...data } = live; + const rendered = await renderMarkdown(readme); + store.set({ + id: file.replace(/\.yaml$/, ''), + data: { ...parsed.data, ...data }, + rendered: { ...rendered, html: cleanReadme(rendered.html, readmeBase) }, + }); + }), + ); + }, + }; +} diff --git a/scripts/registry.mjs b/scripts/registry.mjs index c0dce67..669bf12 100644 --- a/scripts/registry.mjs +++ b/scripts/registry.mjs @@ -87,6 +87,13 @@ async function getJson(url, what) { return response.json(); } +async function getText(url, what) { + const response = await fetch(url); + if (!response.ok) throw new Error(`${what}: ${url} answered ${response.status}`); + + return response.text(); +} + /** The npm packument, reduced to what validation and the card need. */ export async function readNpm(name) { const packument = await getJson(`https://registry.npmjs.org/${name.replace('/', '%2f')}`, `npm ${name}`); @@ -122,8 +129,12 @@ export async function readJsr(name) { const versions = (listing.items ?? []).map((item) => item.version); const newest = newestVersion(versions); const dependencies = newest ? await getJson(`${base}/versions/${newest}/dependencies`, `jsr ${name} deps`) : []; + const meta = newest ? await getJson(`${base}/versions/${newest}`, `jsr ${name} ${newest}`) : {}; + const readme = meta.readmePath + ? await getText(`https://jsr.io/${name}/${newest}${meta.readmePath}`, `jsr ${name} readme`) + : ''; - return { versions, newest, runtimeCompat: info.runtimeCompat ?? {}, dependencies }; + return { versions, newest, runtimeCompat: info.runtimeCompat ?? {}, dependencies, readme }; } /** @@ -142,7 +153,7 @@ export function declaredRuntimes({ engines, runtimeCompat }) { } /** - * Everything one card needs, live. + * Everything a card and a plugin page need, live. * * Under `CI` a registry that does not answer throws and fails the build, which is the rule that * stops a stale or half-empty listing reaching production. Off CI it warns and returns `null`, and @@ -158,12 +169,24 @@ export async function readEntry(entry) { } const jsr = entry.jsr ? await readJsr(entry.jsr) : undefined; + // JSR is the recommendation, so it is the source of the page whenever the entry declares it. + const from = jsr ? { registry: 'jsr', pkg: entry.jsr, info: jsr } : { registry: 'npm', pkg: entry.npm, info: npm }; + const version = from.info.newest; + return { - version: (jsr ?? npm).newest, + registry: from.registry, + pkg: from.pkg, + version, + versions: byNewest(from.info.versions), // npm's `engines` is the richer of the two — JSR's `runtimeCompat` is empty far more often, // including on `@green-tea/core` itself — so it wins when both exist. runtimes: declaredRuntimes({ engines: npm?.engines, runtimeCompat: jsr?.runtimeCompat }), - live: true, + readme: from.info.readme, + // Where the README's relative links point: the files of this exact published version. + readmeBase: + from.registry === 'jsr' + ? `https://jsr.io/${from.pkg}/${version}/` + : `https://cdn.jsdelivr.net/npm/${from.pkg}@${version}/`, }; } catch (error) { if (STRICT) throw error; diff --git a/src/content.config.ts b/src/content.config.ts index d8dd836..8b7dd6e 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -1,5 +1,6 @@ import { defineCollection, z } from 'astro:content'; -import { glob } from 'astro/loaders'; + +import { pluginsLoader } from '../scripts/loader.mjs'; // Naming, from spec 5.2. Enforced here so a wrongly-named submission is rejected by the build // rather than by a reviewer's memory. @@ -8,21 +9,30 @@ import { glob } from 'astro/loaders'; const NPM_NAME = /^(@green-tea\/[a-z0-9-]+|green-tea-[a-z0-9-]+|@[a-z0-9-]+\/green-tea-[a-z0-9-]+)$/; const JSR_NAME = /^@[a-z0-9-]+\/(green-tea-)?[a-z0-9-]+$/; +// `npm` and `jsr` rather than one `name`: a third party's package has a different name on each +// registry. No `version` and no `runtimes` — both come from the registry, so an entry cannot go +// stale or claim a runtime the package never declared. +const FIELDS = z.object({ + npm: z.string().regex(NPM_NAME, 'npm name must be @green-tea/, green-tea- or @scope/green-tea-').optional(), + jsr: z.string().regex(JSR_NAME, 'JSR name must be @scope/').optional(), + repo: z.string().url(), + description: z.string().min(20).max(200), +}); + +const ENTRY = FIELDS.refine((entry) => entry.npm ?? entry.jsr, { + message: 'an entry needs at least one of npm / jsr — otherwise there is nothing to install', +}); + const plugins = defineCollection({ - loader: glob({ pattern: '**/[^_]*.yaml', base: './src/content/plugins' }), - schema: z - .object({ - // `npm` and `jsr` rather than one `name`: a third party's package has a different name on - // each registry. No `version` and no `runtimes` — both come from the registry, so an entry - // cannot go stale or claim a runtime the package never declared. - npm: z.string().regex(NPM_NAME, 'npm name must be @green-tea/, green-tea- or @scope/green-tea-').optional(), - jsr: z.string().regex(JSR_NAME, 'JSR name must be @scope/').optional(), - repo: z.string().url(), - description: z.string().min(20).max(200), - }) - .refine((entry) => entry.npm ?? entry.jsr, { - message: 'an entry needs at least one of npm / jsr — otherwise there is nothing to install', - }), + loader: pluginsLoader(ENTRY), + // What the loader stores: the entry plus what the registry said. + schema: FIELDS.extend({ + pkg: z.string(), + registry: z.enum(['jsr', 'npm']), + version: z.string(), + versions: z.array(z.string()), + runtimes: z.array(z.string()), + }), }); export const collections = { plugins }; diff --git a/src/pages/index.astro b/src/pages/index.astro index c91d886..b1d0a93 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,37 +1,26 @@ --- import { getCollection } from 'astro:content'; -import { readEntry } from '../../scripts/registry.mjs'; import Header from '../components/Header.astro'; import Footer from '../components/Footer.astro'; import PluginCard from '../components/PluginCard.astro'; import '../styles/global.css'; -// Read at build time, never at request time — this site is static files on cPanel. Under CI a -// registry that does not answer fails the build; off CI that entry is left out. See -// scripts/registry.mjs. -const entries = await getCollection('plugins'); -const plugins = ( - await Promise.all( - entries.map(async (entry) => { - const live = await readEntry(entry.data); - if (!live) return null; - - return { - name: entry.data.jsr ?? entry.data.npm, - description: entry.data.description, - repo: entry.data.repo, - npm: entry.data.npm, - jsr: entry.data.jsr, - version: live.version, - runtimes: live.runtimes, - // An internal plugin could be listed on npm alone and still be ours, so check both fields. - internal: (entry.data.jsr ?? entry.data.npm ?? '').startsWith('@green-tea/'), - }; - }), - ) -).filter((plugin) => plugin !== null); - -plugins.sort((a, b) => a.name.localeCompare(b.name)); +// Read at build time by the collection's loader (scripts/loader.mjs) — this site is static files +// on cPanel. Under CI a registry that does not answer fails the build; off CI that entry is left out. +const plugins = (await getCollection('plugins')) + .map(({ id, data }) => ({ + slug: id, + name: data.pkg, + description: data.description, + repo: data.repo, + npm: data.npm, + jsr: data.jsr, + version: data.version, + runtimes: data.runtimes, + // An internal plugin could be listed on npm alone and still be ours, so check both fields. + internal: (data.jsr ?? data.npm ?? '').startsWith('@green-tea/'), + })) + .sort((a, b) => a.name.localeCompare(b.name)); --- -- 2.54.1 From 750781d8394932ff1aff5906eab9698daea67a48 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Thu, 24 Sep 2026 09:56:00 -0500 Subject: [PATCH 04/11] feat: give every plugin a page with its README and versions Clicking a plugin opened nothing; a developer expects what JSR shows. Each page renders the README of the newest version, lists every published version, and gives the install command for the registry the entry recommends. Signed-off-by: Diego Resendez --- src/components/PluginCard.astro | 53 ++----------------- src/components/Runtimes.astro | 56 ++++++++++++++++++++ src/pages/[slug].astro | 94 +++++++++++++++++++++++++++++++++ src/styles/global.css | 33 ++++++++++++ 4 files changed, 188 insertions(+), 48 deletions(-) create mode 100644 src/components/Runtimes.astro create mode 100644 src/pages/[slug].astro diff --git a/src/components/PluginCard.astro b/src/components/PluginCard.astro index 15a6512..ba4049b 100644 --- a/src/components/PluginCard.astro +++ b/src/components/PluginCard.astro @@ -1,13 +1,8 @@ --- -import { RUNTIMES } from '../../scripts/registry.mjs'; -// Brand marks from simple-icons (CC0), vendored rather than pulled at build time. `?raw` inlines -// them so each is one path in the HTML instead of four more requests. -import node from '../icons/nodedotjs.svg?raw'; -import deno from '../icons/deno.svg?raw'; -import bun from '../icons/bun.svg?raw'; -import workerd from '../icons/cloudflareworkers.svg?raw'; +import Runtimes from './Runtimes.astro'; interface Props { + slug: string; name: string; description: string; repo: string; @@ -18,52 +13,14 @@ interface Props { internal: boolean; } -const { name, description, repo, version, npm, jsr, runtimes, internal } = Astro.props; - -const ICONS: Record = { node, deno, bun, workerd }; -const LABELS: Record = { - node: 'Node.js', - deno: 'Deno', - bun: 'Bun', - workerd: 'workerd (Cloudflare Workers)', -}; - -// All four are always shown. Colour means the package declares it runs there; dim grey means it -// declared otherwise, or said nothing — the tooltip is what separates those two, because at a -// glance they are the same fact: you cannot use it there. -const runs = (runtime: string) => runtimes.includes(runtime); -const tooltip = (runtime: string) => { - if (runs(runtime)) return `Runs on ${LABELS[runtime]}`; - - return internal - ? `Does not run on ${LABELS[runtime]} — see the README for why` - : `${LABELS[runtime]} not declared by this package`; -}; +const { slug, name, description, repo, version, npm, jsr, runtimes, internal } = Astro.props; ---
{version} -

{name}

+

{name}

-
    - { - RUNTIMES.map((runtime) => ( - // `data-tip` rather than `title`: the native tooltip waits about a second, cannot be - // styled, and — the reason it did not work at all here — loses to a `` inside the - // SVG. The marks now carry no `<title>`, and the label lives on this element for both the - // tooltip and the screen reader. `tabindex` so it is reachable without a mouse. - <li - class={runs(runtime) ? 'yes' : 'no'} - data-tip={tooltip(runtime)} - role="img" - aria-label={tooltip(runtime)} - tabindex="0" - > - <Fragment set:html={ICONS[runtime]} /> - </li> - )) - } - </ul> + <Runtimes runtimes={runtimes} internal={internal} /> <p>{description}</p> diff --git a/src/components/Runtimes.astro b/src/components/Runtimes.astro new file mode 100644 index 0000000..6535bab --- /dev/null +++ b/src/components/Runtimes.astro @@ -0,0 +1,56 @@ +--- +import { RUNTIMES } from '../../scripts/registry.mjs'; +// Brand marks from simple-icons (CC0), vendored rather than pulled at build time. `?raw` inlines +// them so each is one path in the HTML instead of four more requests. +import node from '../icons/nodedotjs.svg?raw'; +import deno from '../icons/deno.svg?raw'; +import bun from '../icons/bun.svg?raw'; +import workerd from '../icons/cloudflareworkers.svg?raw'; + +interface Props { + runtimes: string[]; + internal: boolean; +} + +const { runtimes, internal } = Astro.props; + +const ICONS: Record<string, string> = { node, deno, bun, workerd }; +const LABELS: Record<string, string> = { + node: 'Node.js', + deno: 'Deno', + bun: 'Bun', + workerd: 'workerd (Cloudflare Workers)', +}; + +// All four are always shown. Colour means the package declares it runs there; dim grey means it +// declared otherwise, or said nothing — the tooltip is what separates those two, because at a +// glance they are the same fact: you cannot use it there. +const runs = (runtime: string) => runtimes.includes(runtime); +const tooltip = (runtime: string) => { + if (runs(runtime)) return `Runs on ${LABELS[runtime]}`; + + return internal + ? `Does not run on ${LABELS[runtime]} — see the README for why` + : `${LABELS[runtime]} not declared by this package`; +}; +--- + +<ul class="runtimes"> + { + RUNTIMES.map((runtime) => ( + // `data-tip` rather than `title`: the native tooltip waits about a second, cannot be + // styled, and — the reason it did not work at all here — loses to a `<title>` inside the + // SVG. The marks now carry no `<title>`, and the label lives on this element for both the + // tooltip and the screen reader. `tabindex` so it is reachable without a mouse. + <li + class={runs(runtime) ? 'yes' : 'no'} + data-tip={tooltip(runtime)} + role="img" + aria-label={tooltip(runtime)} + tabindex="0" + > + <Fragment set:html={ICONS[runtime]} /> + </li> + )) + } +</ul> diff --git a/src/pages/[slug].astro b/src/pages/[slug].astro new file mode 100644 index 0000000..26478e4 --- /dev/null +++ b/src/pages/[slug].astro @@ -0,0 +1,94 @@ +--- +import { getCollection, render } from 'astro:content'; +import Header from '../components/Header.astro'; +import Footer from '../components/Footer.astro'; +import Runtimes from '../components/Runtimes.astro'; +import '../styles/global.css'; + +export async function getStaticPaths() { + return (await getCollection('plugins')).map((entry) => ({ params: { slug: entry.id }, props: { entry } })); +} + +const { entry } = Astro.props; +const { data } = entry; +const { Content } = await render(entry); +const hasReadme = Boolean(entry.rendered?.html); +const internal = data.pkg.startsWith('@green-tea/'); +const install = data.registry === 'jsr' ? `npx jsr add ${data.pkg}` : `npm i ${data.pkg}`; +const versionUrl = (v: string) => + data.registry === 'jsr' ? `https://jsr.io/${data.pkg}@${v}` : `https://www.npmjs.com/package/${data.pkg}/v/${v}`; +const registryUrl = data.registry === 'jsr' ? `https://jsr.io/${data.pkg}` : `https://www.npmjs.com/package/${data.pkg}`; +--- + +<html lang="en"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width" /> + <link rel="icon" href="/plugins/favicon.svg" type="image/svg+xml" /> + <title>{data.pkg} · Green Tea. plugins + + + + +
    + +
    +
    +

    ← All plugins

    +

    {data.pkg} {data.version}

    +

    {data.description}

    + + +
    + {install} + +
    +

    Needs @green-tea/core@26.9.0-beta.2 or newer.

    + + +
    + +
    + + + +
    +
    + +