diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml new file mode 100644 index 0000000..8983d7f --- /dev/null +++ b/.github/workflows/promote.yml @@ -0,0 +1,42 @@ +name: Promote → GitHub + +# Runs on Gitea only, and mirrors two branches to the public GitHub repository, nothing else: +# +# main → GitHub main what gets built and deployed +# develop → GitHub contrib what outside contributors fork from and open pull requests against +# +# Feature branches stay private to Gitea, which is why this is a job and not Gitea's push-mirror: +# a mirror would publish every branch. +# +# Neither push is forced. For `contrib` that is the guard, not a limitation: the push is refused +# exactly when `contrib` holds external merges that have not been carried into `develop` yet. +# Carry them, and the next develop push fast-forwards. This is the same flow as core's promote.yml. +# +# No tags are mirrored. This site has no release tags; a deploy is the Friday cut from `main`. + +on: + push: + branches: [main, develop] + +jobs: + push-github: + if: ${{ github.server_url != 'https://github.com' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # full history for a clean push + - name: Push to GitHub + env: + GH_TOKEN: ${{ secrets.GH_PROMOTE_TOKEN }} + run: | + case "$GITHUB_REF_NAME" in + main) target=main ;; + develop) target=contrib ;; + *) echo "::error::promote runs for main and develop only, got '$GITHUB_REF_NAME'"; exit 1 ;; + esac + git remote add github "https://x-access-token:${GH_TOKEN}@github.com/Expressive-Tea/green-tea-marketplace.git" + if ! git push github "HEAD:refs/heads/${target}"; then + echo "::error::GitHub ${target} has commits that ${GITHUB_REF_NAME} does not. For contrib that means external merges not yet carried into develop — carry them; never force this push." + exit 1 + fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e3a6322 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,44 @@ +# Listing a plugin + +## What counts as a green-tea plugin + +A factory that returns `{ name, mount }`. It imports `@green-tea/core` as types only, with core in +`devDependencies`, so installing the plugin never pulls in a second copy of core. It needs +`@green-tea/core@26.9.0-beta.2` or newer. That is the release where plugins took this shape and +`app.boot()` became public. + +## Where to publish it + +JSR is what we recommend. It records which runtimes a package supports, and the listing shows +that on every card. + +npm works too, as long as the package is ESM only: `"type": "module"`, no `require` condition, and +no `.cjs` file in `main` or `exports`. Dual ESM/CJS packages are turned away. green-tea is ESM from +end to end, and a `require` path is the first thing to break when the Node version floor moves. + +## Add the entry + +Add one file, `src/content/plugins/.yaml`: + +```yaml +jsr: "@your-scope/green-tea-your-plugin" # or npm: green-tea-your-plugin +repo: https://github.com/you/green-tea-your-plugin +description: "One sentence, 20 to 200 characters." +``` + +Names follow one pattern per registry: `green-tea-` or `@scope/green-tea-` on npm, +`@scope/` on JSR. There is no version field and no runtimes field. The listing reads both from +the registry, so your entry can't go stale. + +## What gets checked + +The build checks two things on its own: the package exists on the registry you named, and an npm +package is ESM only. A package that fails either one is not listed. + +A person checks the rest. The package has to be a factory returning `{ name, mount }` and keep +core as a type-only dependency. Its README has to cover all four runtimes (Node, Deno, Bun, +workerd) and give a reason next to each one it doesn't support. + +## When it goes live + +Merged entries go out with the next Friday cut. diff --git a/package-lock.json b/package-lock.json index 056d767..f80757d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,9 @@ "version": "26.9.0", "dependencies": { "@astrojs/sitemap": "^3.7.3", - "astro": "^7.1.6" + "astro": "^7.1.6", + "js-yaml": "^4.3.2", + "sanitize-html": "^2.17.7" }, "engines": { "node": ">=22.12.0" @@ -2298,6 +2300,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 +2496,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 +2704,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 +2847,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 +2884,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 +3465,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 +3651,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 bd120ac..9ae2a6a 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,14 @@ "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" }, "dependencies": { "@astrojs/sitemap": "^3.7.3", - "astro": "^7.1.6" + "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/preview.mjs b/scripts/preview.mjs deleted file mode 100644 index df78b9b..0000000 --- a/scripts/preview.mjs +++ /dev/null @@ -1,14 +0,0 @@ -// What the seed plugins declare, copied from their `package.json` in Green-Tea/plugins. -// -// This exists so the site can be designed and reviewed before the packages ship. It is used ONLY -// when a registry has no answer and `CI` is unset — in GitHub Actions a missing package fails the -// build instead, which is where the real check lives. -// -// **Delete this file, and its import in `src/pages/index.astro`, once the three are published.** -// Every entry here is a claim nobody verified; the registry is the source of truth and this is a -// stand-in for a registry that does not have the package yet. -export const PREVIEW = { - '@green-tea/jwt': { version: '26.9.0-beta.0', engines: { node: '>=22', deno: '>=2', bun: '>=1.3' } }, - '@green-tea/metrics': { version: '26.9.0-beta.0', engines: { node: '>=22', deno: '>=2', bun: '>=1.3' } }, - '@green-tea/rate-limit': { version: '26.9.0-beta.0', engines: { node: '>=22', deno: '>=2', bun: '>=1.3' } }, -}; diff --git a/scripts/readme.mjs b/scripts/readme.mjs new file mode 100644 index 0000000..2ce8670 --- /dev/null +++ b/scripts/readme.mjs @@ -0,0 +1,71 @@ +// 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$/] }, + }, + // Only the classes shiki writes, spelled out. A README that could use any class could borrow the + // site's own (`card__link::after` is a full-page overlay) and draw over the page that way. + // `github-dark` is Astro's default theme; change it here if astro.config.mjs picks another. + allowedClasses: { + pre: ['astro-code', 'github-dark'], + code: [/^language-[a-z0-9+#-]+$/], + span: ['line'], + }, + allowedSchemes: ['http', 'https', 'mailto'], + transformTags: { + a: (tagName, attribs) => ({ tagName, attribs: rebase(attribs, 'href', base) }), + img: (tagName, attribs) => ({ tagName, attribs: rebase(attribs, 'src', base) }), + // `srcset` is a comma-separated list of "url descriptor" pairs; only the url moves. + source: (tagName, attribs) => + 'srcset' in attribs + ? { + tagName, + attribs: { + ...attribs, + srcset: attribs.srcset + .split(',') + .map((candidate) => { + const [url, ...descriptor] = candidate.trim().split(/\s+/); + return [absolute(url, base), ...descriptor].join(' '); + }) + .join(', '), + }, + } + : { tagName, attribs }, + }, + }); +} diff --git a/scripts/registry.mjs b/scripts/registry.mjs index f749535..33104b6 100644 --- a/scripts/registry.mjs +++ b/scripts/registry.mjs @@ -10,8 +10,8 @@ export const RUNTIMES = Object.freeze(['node', 'deno', 'bun', 'workerd']); * * In GitHub Actions a package that does not answer is a failure — that is the check, and it runs * against the live registries on every pull request and every push to main. Locally it is a - * warning and the card renders from `preview.mjs`, because a site you cannot look at until its - * packages ship is a site nobody can design. + * warning and the entry is left out, so the site can still be looked at while one package is + * broken — without rendering data nobody read from a registry. */ export const STRICT = process.env.CI === 'true'; @@ -48,7 +48,41 @@ 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); +} + +/** JSR's version list minus yanked ones — the registry hides those, so the listing must too. */ +export function publishedVersions(items) { + return items.filter((item) => !item.yanked).map((item) => item.version); +} + +/** 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) { @@ -58,6 +92,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}`); @@ -76,6 +117,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), }; } @@ -86,11 +131,15 @@ export async function readJsr(name) { const info = await getJson(base, `jsr ${name}`); const listing = await getJson(`${base}/versions`, `jsr ${name} versions`); // `items`, not `latestVersion`. See newestVersion. - const versions = (listing.items ?? []).map((item) => item.version); + const versions = publishedVersions(listing.items ?? []); 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 }; } /** @@ -109,30 +158,45 @@ export function declaredRuntimes({ engines, runtimeCompat }) { } /** - * Everything one card needs, live where possible. + * 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 falls back to `preview.mjs` - * and says so, loudly, once per package. + * stops a stale or half-empty listing reaching production. Off CI it warns and returns `null`, and + * the caller leaves the entry out. */ -export async function readEntry(entry, preview) { +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; + // 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: (npm ?? jsr).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; - const fallback = preview[entry.npm ?? entry.jsr]; - if (!fallback) throw error; - console.warn(` not published yet, rendering from preview data: ${entry.npm ?? entry.jsr}`); + console.warn(` left out: ${entry.jsr ?? entry.npm} (${error.message})`); - return { version: fallback.version, runtimes: declaredRuntimes({ engines: fallback.engines }), live: false }; + return null; } } diff --git a/scripts/registry.test.mjs b/scripts/registry.test.mjs new file mode 100644 index 0000000..f000b4b --- /dev/null +++ b/scripts/registry.test.mjs @@ -0,0 +1,99 @@ +// 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, publishedVersions } 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); +}); + +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'); +}); + +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/); +}); + +test('cleanReadme: our own class names cannot be borrowed, shiki ones stay', () => { + const html = cleanReadme( + 'xy
z
', + BASE, + ); + assert.doesNotMatch(html, /card__link|class="version"/); + assert.match(html, /class="astro-code github-dark"/); + assert.match(html, /class="line"/); + assert.match(html, /class="language-ts"/); +}); + +test('cleanReadme: points at the published version, descriptors kept', () => { + const html = cleanReadme('', BASE); + assert.match(html, /srcset="https:\/\/jsr\.io\/@green-tea\/jwt\/26\.9\.0-beta\.0\/docs\/dark\.svg, https:\/\/jsr\.io\/@green-tea\/jwt\/26\.9\.0-beta\.0\/docs\/dark@2x\.svg 2x"/); +}); + +test('publishedVersions: yanked JSR versions are not listed', () => { + assert.deepEqual(publishedVersions([{ version: '1.0.0', yanked: false }, { version: '1.0.1', yanked: true }]), ['1.0.0']); +}); diff --git a/src/components/Footer.astro b/src/components/Footer.astro index ea0ce10..2409cfa 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -8,7 +8,7 @@ const linkColumns = [ { heading: 'This listing', links: [ - { label: 'Add your plugin', href: '#contribute', external: false }, + { label: 'Add your plugin', href: '/plugins/#contribute', external: false }, { label: 'Source', href: 'https://github.com/Expressive-Tea/green-tea-marketplace', diff --git a/src/components/Header.astro b/src/components/Header.astro index c1c99a3..3cd436b 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -6,7 +6,7 @@ import Icon from './Icon.astro'; // what this one is. The logo links out to green-tea rather than to `/`, because a reader who // clicks a brand mark is asking for the project, and the project lives elsewhere. const navLinks = [ - { label: 'Add your plugin', href: '#contribute', external: false }, + { label: 'Add your plugin', href: '/plugins/#contribute', external: false }, { label: 'Docs', href: 'https://green-tea.expressive-tea.io/docs', external: true }, { label: 'green-tea', href: 'https://green-tea.expressive-tea.io', external: true }, { 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/components/sections/FrontRow.astro b/src/components/sections/FrontRow.astro new file mode 100644 index 0000000..5509b5d --- /dev/null +++ b/src/components/sections/FrontRow.astro @@ -0,0 +1,47 @@ +--- +import { ADD_URL, CONTRIBUTING_URL } from '../../links'; +--- + +<section class="section wrap"> + <div class="front"> + <h2>The listing is new. The first plugins get the front row.</h2> + <p>Every plugin here today is one of ours. The first community entries are the ones people will see first.</p> + <p class="front__actions"> + <a class="button button--solid" href={ADD_URL}>Add your plugin</a> + <a class="button button--ghost" href={CONTRIBUTING_URL}>Read CONTRIBUTING.md</a> + </p> + </div> +</section> + +<style> + .front { + text-align: center; + padding: clamp(2.5rem, 6vw, 4rem) clamp(1.5rem, 5vw, 3rem); + border: 1px solid var(--line); + border-radius: 16px; + background: + radial-gradient(ellipse at top, rgba(95, 184, 138, 0.14), transparent 60%), + radial-gradient(ellipse at bottom, rgba(124, 108, 240, 0.1), transparent 60%), + var(--panel); + } + + .front h2 { + font-size: clamp(1.5rem, 4vw, 2.2rem); + margin: 0 auto 14px; + max-width: 24ch; + } + + .front p { + color: var(--dim); + margin: 0 auto; + max-width: 56ch; + } + + .front__actions { + display: flex; + gap: 0.75rem; + justify-content: center; + flex-wrap: wrap; + margin-top: 1.75rem !important; + } +</style> diff --git a/src/components/sections/Hero.astro b/src/components/sections/Hero.astro new file mode 100644 index 0000000..6e9f67e --- /dev/null +++ b/src/components/sections/Hero.astro @@ -0,0 +1,126 @@ +--- +import { Code } from 'astro:components'; +import { ADD_URL } from '../../links'; + +// A whole plugin, written against the real `Plugin` type in core (src/plugin.ts). If that type +// changes, this has to change with it — it is the first thing a plugin author reads. +const SAMPLE = `import type { Plugin } from '@green-tea/core'; + +export function greeting(text = 'hello'): Plugin { + return { + name: 'greeting', + mount({ scope }) { + scope.add({ + kind: 'provider', + name: 'greeting', + needs: [], + provides: ['greeting'], + run: () => ({ greeting: text }), + }); + }, + }; +}`; +--- + +<section class="hero"> + <div class="wrap hero__grid"> + <div class="hero__content"> + <p class="kicker">Green Tea. plugins</p> + <h1>Write it once. It mounts in any <span class="nowrap">green-tea</span> app.</h1> + <p class="hero__lead"> + A plugin is a name and a mount function. It adds providers and steps to the graph, and + green-tea figures out where they run. Publish it to JSR or npm, list it here, and it gets a + page of its own. + </p> + <p class="hero__actions"> + <a class="button button--solid" href={ADD_URL}>Add your plugin</a> + <a class="button button--ghost" href="#plugins">Browse plugins</a> + </p> + <p class="hero__micro">Needs <code>@green-tea/core@26.9.0-beta.2</code> or newer. Each card shows which runtimes that plugin supports.</p> + </div> + + <figure class="hero__code" aria-label="A complete plugin"> + <figcaption>greeting.ts</figcaption> + <Code code={SAMPLE} lang="ts" theme="github-dark" /> + </figure> + </div> +</section> + +<style> + .hero { + padding-block: clamp(3rem, 8vw, 5.5rem) clamp(2rem, 5vw, 3.5rem); + } + + .hero__grid { + display: grid; + grid-template-columns: minmax(0, 1fr) minmax(0, 460px); + align-items: center; + gap: clamp(2rem, 5vw, 3.5rem); + } + + .hero h1 { + font-size: clamp(2.2rem, 5.5vw, 3.3rem); + line-height: 1.15; + margin: 0 0 18px; + letter-spacing: -0.01em; + } + + .hero__lead { + color: var(--dim); + max-width: 52ch; + margin: 0; + font-size: 1.08rem; + line-height: 1.7; + } + + .hero__actions { + display: flex; + gap: 0.75rem; + flex-wrap: wrap; + margin: 1.75rem 0 1.25rem; + } + + .hero__micro { + margin: 0; + color: var(--dim); + font-size: 0.85rem; + letter-spacing: 0.03em; + } + + .hero__micro code { + font-family: var(--font-mono); + color: var(--ink); + } + + .hero__code { + margin: 0; + background: var(--panel); + border: 1px solid var(--line); + border-radius: 12px; + overflow: hidden; + box-shadow: 0 24px 60px -30px rgba(95, 184, 138, 0.35); + } + + .hero__code figcaption { + padding: 10px 16px; + border-bottom: 1px solid var(--line); + color: var(--dim); + font-family: var(--font-mono); + font-size: 0.78rem; + } + + .hero__code :global(pre) { + margin: 0; + padding: 16px 18px; + background: transparent !important; + font-size: 0.8rem; + line-height: 1.65; + overflow-x: auto; + } + + @media (max-width: 900px) { + .hero__grid { + grid-template-columns: 1fr; + } + } +</style> diff --git a/src/components/sections/HowItWorks.astro b/src/components/sections/HowItWorks.astro new file mode 100644 index 0000000..19f7602 --- /dev/null +++ b/src/components/sections/HowItWorks.astro @@ -0,0 +1,89 @@ +--- +import { Code } from 'astro:components'; +import { EXAMPLE_ENTRY } from '../../links'; + +// The editor gets the comment that explains npm; the card is too narrow for it. +const shown = EXAMPLE_ENTRY.replace(/[ \t]+#.*$/m, '').trim(); +--- + +<section class="section wrap" id="contribute"> + <p class="kicker">How it works</p> + <h2>Three steps</h2> + + <ol class="steps"> + <li class="step"> + <h3>Publish</h3> + <p>Put it on JSR, or on npm as an ESM-only package.</p> + </li> + <li class="step step--wide"> + <h3>Add one file</h3> + <p>Open a pull request that adds one yaml file.</p> + <Code code={shown} lang="yaml" theme="github-dark" /> + </li> + <li class="step"> + <h3>Go live</h3> + <p>Once it merges, it is out on the next Friday cut.</p> + </li> + </ol> +</section> + +<style> + .steps { + list-style: none; + counter-reset: step; + padding: 0; + margin: 0; + display: grid; + grid-template-columns: 1fr minmax(0, 2fr) 1fr; + gap: 20px; + } + + .step { + counter-increment: step; + background: var(--panel); + border: 1px solid var(--line); + border-radius: 12px; + padding: 22px 24px; + min-width: 0; + } + + .step::before { + content: counter(step); + display: inline-grid; + place-items: center; + width: 30px; + height: 30px; + border-radius: 50%; + background: rgba(95, 184, 138, 0.12); + border: 1px solid rgba(95, 184, 138, 0.35); + color: var(--matcha); + font-family: var(--font-mono); + font-size: 0.85rem; + } + + .step h3 { + margin: 12px 0 6px; + font-size: 1.1rem; + } + + .step p { + margin: 0; + color: var(--dim); + } + + .step :global(pre) { + margin: 14px 0 0; + padding: 12px 14px; + border-radius: 8px; + border: 1px solid var(--line); + font-size: 0.76rem; + line-height: 1.6; + overflow-x: auto; + } + + @media (max-width: 900px) { + .steps { + grid-template-columns: 1fr; + } + } +</style> diff --git a/src/components/sections/WhatIsAPlugin.astro b/src/components/sections/WhatIsAPlugin.astro new file mode 100644 index 0000000..4eebae7 --- /dev/null +++ b/src/components/sections/WhatIsAPlugin.astro @@ -0,0 +1,84 @@ +--- +// Every claim here is checked against core: the shape and the three-method API are +// `Plugin`/`PluginApi` in src/plugin.ts, and `mountPlugin` hands over nothing else. +// +// Make no isolation claims here at all. A plugin's step gets the live request context and can +// overwrite keys in it (see mountPlugin's comment), and a plugin node can replace an app step: a +// plugin node that +// provides a token an app step already provides wins in `topoSort`/`subgraphFor` (src/graph.ts, +// `producedBy.set`, last one in), and the app's step drops out of the graph with no error. +// Verified 2026-09-24. Only duplicate node *names* are a boot error. +// +// The claim is execution order derived from needs/provides, and nothing more. Registration order +// is NOT irrelevant: with two producers of one token, the one registered last wins, so never +// write "no need to register X first". +const points = [ + { + title: 'One object', + body: '<code>{ name, mount }</code>. No base class to extend and no lifecycle to learn. <code>mount</code> gets <code>bus.on</code>, <code>scope.add</code> and <code>onShutdown</code>, and that is the whole API.', + }, + { + title: 'Core as types only', + body: 'Plugins import <code>@green-tea/core</code> with <code>import type</code> and keep it out of <code>dependencies</code>, and review checks for it. So installing one does not pull in a second copy of core.', + }, + { + title: 'The graph picks the order', + body: 'Say what your plugin needs and what it provides, and green-tea works out where it runs.', + }, +]; +--- + +<section class="section wrap"> + <p class="kicker">The idea</p> + <h2>What's a plugin, and why write one?</h2> + + <div class="points"> + { + points.map((point, i) => ( + <article class="point"> + <span class="point__n" aria-hidden="true">{String(i + 1).padStart(2, '0')}</span> + <h3>{point.title}</h3> + <p set:html={point.body} /> + </article> + )) + } + </div> +</section> + +<style> + .points { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); + gap: 20px; + } + + .point { + background: var(--panel); + border: 1px solid var(--line); + border-radius: 12px; + padding: 22px 24px; + } + + .point__n { + font-family: var(--font-mono); + font-size: 0.78rem; + color: var(--violet); + } + + .point h3 { + margin: 6px 0 10px; + font-size: 1.15rem; + } + + .point p { + margin: 0; + color: var(--dim); + line-height: 1.65; + } + + .point :global(code) { + font-family: var(--font-mono); + font-size: 0.88em; + color: var(--matcha); + } +</style> diff --git a/src/components/sections/WhyHere.astro b/src/components/sections/WhyHere.astro new file mode 100644 index 0000000..5c402b7 --- /dev/null +++ b/src/components/sections/WhyHere.astro @@ -0,0 +1,55 @@ +--- +// Nothing here promises traffic or reach. Each line is something the listing already does. +const reasons = [ + { title: 'A page of its own', body: 'Your README, every published version and an install command people can copy.' }, + { title: 'Runtimes read, not typed', body: 'Each card shows where your plugin runs, taken from what the package declares.' }, + { + title: "It doesn't go stale", + body: 'Your entry has no version in it. Each rebuild of the listing asks the registry again, so your card picks up a new release without you touching the entry.', + }, + { title: 'Read by a person', body: 'Someone who works on green-tea reads each entry before it is listed.' }, +]; +--- + +<section class="section wrap"> + <p class="kicker">Why here</p> + <h2>Why list it here</h2> + + <dl class="reasons"> + { + reasons.map((reason) => ( + <div class="reason"> + <dt>{reason.title}</dt> + <dd>{reason.body}</dd> + </div> + )) + } + </dl> +</section> + +<style> + .reasons { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); + gap: 28px 36px; + margin: 0; + } + + .reason { + border-left: 2px solid var(--matcha); + padding-left: 16px; + } + + .reason dt { + font-family: var(--font-heading); + font-weight: 700; + font-size: 1.05rem; + margin-bottom: 6px; + } + + .reason dd { + margin: 0; + color: var(--dim); + line-height: 1.65; + } +</style> 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/<x>, green-tea-<x> or @scope/green-tea-<x>').optional(), + jsr: z.string().regex(JSR_NAME, 'JSR name must be @scope/<x>').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/<x>, green-tea-<x> or @scope/green-tea-<x>').optional(), - jsr: z.string().regex(JSR_NAME, 'JSR name must be @scope/<x>').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/content/plugins/jwt.yaml b/src/content/plugins/jwt.yaml index 5fdafde..0d3c8e4 100644 --- a/src/content/plugins/jwt.yaml +++ b/src/content/plugins/jwt.yaml @@ -1,4 +1,3 @@ -npm: "@green-tea/jwt" jsr: "@green-tea/jwt" repo: https://github.com/Expressive-Tea/green-tea-plugins description: "Loads JWT signing keys at boot and publishes a sign/verify registry into the graph." diff --git a/src/content/plugins/metrics.yaml b/src/content/plugins/metrics.yaml index c31517c..846b3ad 100644 --- a/src/content/plugins/metrics.yaml +++ b/src/content/plugins/metrics.yaml @@ -1,4 +1,3 @@ -npm: "@green-tea/metrics" jsr: "@green-tea/metrics" repo: https://github.com/Expressive-Tea/green-tea-plugins description: "Counts green-tea's lifecycle events and renders them in the Prometheus text format." diff --git a/src/content/plugins/rate-limit.yaml b/src/content/plugins/rate-limit.yaml index f5e0aea..6b640ce 100644 --- a/src/content/plugins/rate-limit.yaml +++ b/src/content/plugins/rate-limit.yaml @@ -1,4 +1,3 @@ -npm: "@green-tea/rate-limit" jsr: "@green-tea/rate-limit" repo: https://github.com/Expressive-Tea/green-tea-plugins description: "A per-request rate limiter with a branded 429 and a swept in-memory store." diff --git a/src/links.ts b/src/links.ts new file mode 100644 index 0000000..47ce31e --- /dev/null +++ b/src/links.ts @@ -0,0 +1,13 @@ +// Links more than one section needs. The GitHub repo does not exist yet, so these 404 until it does. + +/** What "Add your plugin" pre-fills in GitHub's new-file editor. */ +export const EXAMPLE_ENTRY = `jsr: "@your-scope/green-tea-your-plugin" # recommended. Or npm: green-tea-your-plugin (ESM only) +repo: https://github.com/you/green-tea-your-plugin +description: "One sentence, 20 to 200 characters." +`; + +// GitHub's new-file editor, inside this repo, with the example already filled in: a contributor +// edits a few lines and opens the pull request from there. +export const ADD_URL = `https://github.com/Expressive-Tea/green-tea-marketplace/new/main/src/content/plugins?filename=green-tea-your-plugin.yaml&value=${encodeURIComponent(EXAMPLE_ENTRY)}`; + +export const CONTRIBUTING_URL = 'https://github.com/Expressive-Tea/green-tea-marketplace/blob/main/CONTRIBUTING.md'; 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.

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