Repository navigation
feat: implement metadata worker for npm and GitHub integration with c… - #93
Merged
Merged
Conversation
Contributor
⚡ Successfully deployed to Cloudflare Pages!
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Version-qualified package names cause entire npm-version fields to fail, and the 15-second deadline can time out otherwise successful cold-cache GitHub lookups.
2 open issues
What changed in this PR
Adds live npm and GitHub metadata to the plugin directory through browser resolvers and a separate Cloudflare Worker.
Changes:
- Adds cached endpoints for npm versions, GitHub releases, and recent commits.
- Configures showcase computed fields and upgrades the showcase plugin to 1.3.0.
- Adds tests, deployment automation, and setup documentation.
| File | Description |
|---|---|
yarn.lock |
Locks the showcase plugin upgrade. |
workers/metadata/wrangler.jsonc |
Configures the Worker and allowed origins. |
workers/metadata/worker.mjs |
Implements metadata endpoints, validation, caching, and CORS. |
workers/metadata/package.json |
Isolates Worker tooling from the website project. |
workers/metadata/LICENSE |
Adds licensing information for adapted code. |
tests/showcase-metadata.test.mjs |
Tests Worker endpoints and browser resolvers. |
src/utils/showcaseMetadata.ts |
Adds cached npm and GitHub metadata resolvers. |
README.md |
Documents configuration, testing, and deployment. |
package.json |
Upgrades the showcase plugin to 1.3.0. |
docusaurus.config.ts |
Enables metadata fields when an endpoint is configured. |
.github/workflows/publish.yml |
Tests and deploys the Worker and supplies its endpoint to website builds. |
Review effort: Balanced
| const url = new URL(path, `${endpoint.replace(/\/$/, '')}/`).href | ||
| const cached = requests.get(url) | ||
| if (cached && cached.expires > Date.now()) return cached.promise | ||
| const promise = fetch(url, { signal: AbortSignal.timeout(15_000) }).then(async (response) => { |
| export const npmVersions: ComputedFieldResolver = async (item, context) => { | ||
| if (!item.npmPackages?.length) return null | ||
| return (await Promise.all(item.npmPackages.map((name) => | ||
| metadata(`npm?package=${encodeURIComponent(name)}`, context)))).flat() |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

…aching