-
Notifications
You must be signed in to change notification settings - Fork 27
feat(web): introduce stability overview
#644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -253,7 +253,7 @@ export const transformHeadingNode = async ( | |
| * @param {ApiDocMetadataEntry} entry - The API metadata entry to process | ||
| * @param {import('unified').Processor} remark - The remark processor | ||
| */ | ||
| export const processEntry = (entry, remark) => { | ||
| export const processEntry = (entry, remark, stabilityOverviewEntries = []) => { | ||
| // Deep copy content to avoid mutations on original | ||
| const content = structuredClone(entry.content); | ||
|
|
||
|
|
@@ -272,6 +272,18 @@ export const processEntry = (entry, remark) => { | |
| (node, idx, parent) => (parent.children[idx] = createPropertyTable(node)) | ||
| ); | ||
|
|
||
| // Inject the stability overview table where the slot tag is present | ||
| if ( | ||
| stabilityOverviewEntries.length && | ||
| entry.tags.includes('STABILITY_OVERVIEW_SLOT_BEGIN') | ||
| ) { | ||
| content.children.push( | ||
| createJSXElement(JSX_IMPORTS.StabilityOverview.name, { | ||
| entries: stabilityOverviewEntries, | ||
| }) | ||
| ); | ||
| } | ||
|
Comment on lines
+275
to
+285
|
||
|
|
||
| return content; | ||
| }; | ||
|
|
||
|
|
@@ -286,7 +298,8 @@ export const createDocumentLayout = ( | |
| entries, | ||
| sideBarProps, | ||
| metaBarProps, | ||
| remark | ||
| remark, | ||
| stabilityOverviewEntries = [] | ||
| ) => | ||
| createTree('root', [ | ||
| createJSXElement(JSX_IMPORTS.NavBar.name), | ||
|
|
@@ -302,7 +315,9 @@ export const createDocumentLayout = ( | |
| createElement('br'), | ||
| createElement( | ||
| 'main', | ||
| entries.map(entry => processEntry(entry, remark)) | ||
| entries.map(entry => | ||
| processEntry(entry, remark, stabilityOverviewEntries) | ||
| ) | ||
| ), | ||
| ]), | ||
| createJSXElement(JSX_IMPORTS.MetaBar.name, metaBarProps), | ||
|
|
@@ -321,7 +336,13 @@ export const createDocumentLayout = ( | |
| * @param {import('unified').Processor} remark - Remark processor instance for markdown processing | ||
| * @returns {Promise<JSXContent>} | ||
| */ | ||
| const buildContent = async (metadataEntries, head, sideBarProps, remark) => { | ||
| const buildContent = async ( | ||
| metadataEntries, | ||
| head, | ||
| sideBarProps, | ||
| remark, | ||
| stabilityOverviewEntries = [] | ||
| ) => { | ||
| // Build props for the MetaBar from head and entries | ||
| const metaBarProps = buildMetaBarProps(head, metadataEntries); | ||
|
|
||
|
|
@@ -330,7 +351,8 @@ const buildContent = async (metadataEntries, head, sideBarProps, remark) => { | |
| metadataEntries, | ||
| sideBarProps, | ||
| metaBarProps, | ||
| remark | ||
| remark, | ||
| stabilityOverviewEntries | ||
| ); | ||
|
|
||
| // Run remark processor to transform AST (parse markdown, plugins, etc.) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| 'use strict'; | ||
|
|
||
| import { readFile, writeFile } from 'node:fs/promises'; | ||
| import { mkdir, readFile, writeFile } from 'node:fs/promises'; | ||
| import { createRequire } from 'node:module'; | ||
| import { join } from 'node:path'; | ||
|
|
||
|
|
@@ -35,6 +35,8 @@ export async function generate(input) { | |
|
|
||
| // Process all entries together (required for code-split bundles) | ||
| if (config.output) { | ||
| await mkdir(config.output, { recursive: true }); | ||
|
|
||
|
Comment on lines
+38
to
+39
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated, and this type of change was blocked previously |
||
| // Write HTML files | ||
| for (const { html, api } of results) { | ||
| await writeFile(join(config.output, `${api}.html`), html, 'utf-8'); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than adding a new JSX component, which requires serializing and passing more data to the client, can't we just generate the AST in a new file, similarly to how was done with the property table (before it was replaced)? |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,56 @@ | ||||||||
| import Badge from '@node-core/ui-components/Common/Badge'; | ||||||||
|
|
||||||||
| import styles from './index.module.css'; | ||||||||
|
|
||||||||
| const STABILITY_KINDS = ['error', 'warning', 'success', 'info']; | ||||||||
| const STABILITY_TOOLTIPS = ['Deprecated', 'Experimental', 'Stable', 'Legacy']; | ||||||||
|
|
||||||||
| /** | ||||||||
| * @typedef StabilityOverviewEntry | ||||||||
| * @property {string} api - The API identifier (basename, e.g. "fs") | ||||||||
| * @property {string} name - The human-readable display name of the API module | ||||||||
| * @property {number} stabilityIndex - The stability level index (0–3) | ||||||||
| * @property {string} stabilityDescription - First sentence of the stability description | ||||||||
| */ | ||||||||
|
|
||||||||
| /** | ||||||||
| * Renders a table summarising the stability level of each API module. | ||||||||
| * | ||||||||
| * @param {{ entries: Array<StabilityOverviewEntry> }} props | ||||||||
| */ | ||||||||
| export default ({ entries = [] }) => { | ||||||||
| if (!entries.length) { | ||||||||
| return null; | ||||||||
| } | ||||||||
|
|
||||||||
| return ( | ||||||||
| <table className={styles.table}> | ||||||||
| <thead> | ||||||||
| <tr> | ||||||||
| <th>API</th> | ||||||||
| <th>Stability</th> | ||||||||
| </tr> | ||||||||
| </thead> | ||||||||
| <tbody> | ||||||||
| {entries.map(({ api, name, stabilityIndex, stabilityDescription }) => ( | ||||||||
| <tr key={api}> | ||||||||
| <td> | ||||||||
| <a href={`${api}.html`}>{name}</a> | ||||||||
| </td> | ||||||||
| <td className={styles.stabilityCell}> | ||||||||
| <Badge | ||||||||
| kind={STABILITY_KINDS[stabilityIndex]} | ||||||||
| data-tooltip={STABILITY_TOOLTIPS[stabilityIndex]} | ||||||||
| aria-label={`Stability: ${STABILITY_TOOLTIPS[stabilityIndex]}`} | ||||||||
|
||||||||
| aria-label={`Stability: ${STABILITY_TOOLTIPS[stabilityIndex]}`} | |
| aria-label={`Stability: ${STABILITY_TOOLTIPS[stabilityIndex]}`} | |
| tabIndex={0} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| .table { | ||
| width: 100%; | ||
| } | ||
|
|
||
| .stabilityCell { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.4rem; | ||
| flex-wrap: wrap; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processEntry()appends the<StabilityOverview />element tocontent.children, which places the table at the end of the section. In the legacy HTML generator the stability overview is injected near the top of the target section (viabuildExtraContent, before the rest of the nodes), so this likely changes the intended placement of the slot. Consider inserting the overview at a deterministic position (e.g., right after the section heading / before the main body), or otherwise aligning placement with the slot semantics used inlegacy-html.