Skip to content

feat(typemap): refresh from mdn#686

Open
avivkeller wants to merge 5 commits intomainfrom
fix-type-map
Open

feat(typemap): refresh from mdn#686
avivkeller wants to merge 5 commits intomainfrom
fix-type-map

Conversation

@avivkeller
Copy link
Member

Fixes #683 by adding an update script that reads directly from MDN.

@avivkeller avivkeller requested a review from a team as a code owner March 17, 2026 17:15
Copilot AI review requested due to automatic review settings March 17, 2026 17:15
@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview Mar 21, 2026 2:51pm

Request Review

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 26.19048% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.62%. Comparing base (0f69d7b) to head (40018a5).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
scripts/update-type-map.mjs 0.00% 26 Missing ⚠️
src/generators/metadata/utils/transformers.mjs 61.53% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #686      +/-   ##
==========================================
- Coverage   75.95%   75.62%   -0.34%     
==========================================
  Files         149      150       +1     
  Lines       13648    13627      -21     
  Branches     1040     1039       -1     
==========================================
- Hits        10367    10305      -62     
- Misses       3275     3316      +41     
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses incorrect/unstable external type reference URLs by switching metadata type linkification to a refreshed MDN-derived type map, and adds automation to keep that map up to date (fixing cases like the double // in MDN links noted in #683).

Changes:

  • Replace hardcoded MDN type mappings with a generated typeMap.json consumed by transformTypeToReferenceLink.
  • Add a script + scheduled GitHub Action workflow to regenerate the type map from MDN browser-compat-data releases.
  • Remove now-unneeded MDN mapping constants and adjust dependency placement.

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/generators/metadata/utils/transformers.mjs Switches type resolution to use the new MDN-generated JSON type map.
src/generators/metadata/typeMap.json Replaces the prior small map with a large MDN-derived mapping of types to canonical URLs.
src/generators/metadata/constants.mjs Removes MDN-specific constants/mappings that are no longer used.
scripts/update-type-map.mjs New generator script to fetch MDN browser-compat-data and write typeMap.json.
.github/workflows/update-type-map.yml New scheduled workflow to run the generator and open/update a PR automatically.
package.json Bumps version and moves globals to devDependencies.
package-lock.json Locks the dependency move + version bump.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.


const compat = JSON.parse(
await loadFromURL(
'https://github.com/mdn/browser-compat-data/releases/latest/download/data.json'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: make this a constant on our shared constants file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What shared constants file? This is a script, not a constant used in prod?

const creatingMapping = obj =>
Object.fromEntries(
Object.entries(obj)
.map(([k, v]) => [k.toLowerCase(), v.__compat.mdn_url])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this typed? can you add an inline jsdoc with @see referring where this comes from if anywhere? :3

Copy link
Member Author

@avivkeller avivkeller Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no. Yes, there is a typed version, but it's another npm dependency, so we use the URL that the dependency is published from

};

writeFile(
'./src/generators/metadata/maps/mdn.json',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if we have destination files as constants in generators, it'd be good to have it here too. But that's a small nit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't


writeFile(
'./src/generators/metadata/maps/mdn.json',
JSON.stringify(map, null, 2) + '\n'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need an extra line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier requires files to end with a newline

} from '../constants.mjs';
import { slug } from './slugger.mjs';
import { transformNodesToString } from '../../../utils/unist.mjs';
import HARDCODED_TYPE_MAP from '../maps/hardcoded.json' with { type: 'json' };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we call this file something else? like something more intuitive/explanatory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like what?


defaultConfiguration: {
typeMap: import.meta.resolve('./typeMap.json'),
typeMap: import.meta.resolve('./maps/hardcoded.json'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used? I don't see references anywhere in the code?

Copy link
Member Author

@avivkeller avivkeller Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In generate.mjs:

/**
 * Generates a flattened list of metadata entries from API docs.
 *
 * @type {import('./types').Generator['generate']}
 */
export async function* generate(inputs, worker) {
  const { metadata: config } = getConfig();

  const typeMap = await importFromURL(config.typeMap);

  // Stream chunks as they complete - allows dependent generators
  // to start collecting/preparing while we're still processing
  for await (const chunkResult of worker.stream(inputs, typeMap)) {
    yield chunkResult.flat();
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web globals have an invalid URL

6 participants