Skip to content

Commit b2181a2

Browse files
authored
chore: attempt to improve hdyration (#516)
1 parent 0e07e21 commit b2181a2

File tree

13 files changed

+68
-36
lines changed

13 files changed

+68
-36
lines changed

bin/commands/generate.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export default {
148148
await runGenerators({
149149
generators: opts.target,
150150
input: opts.input,
151+
ignore: opts.ignore,
151152
output: opts.output && resolve(opts.output),
152153
version: coerce(opts.version),
153154
releases: await parseChangelog(opts.changelog),

npm-shrinkwrap.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"lightningcss": "^1.30.2",
6262
"mdast-util-slice-markdown": "^2.0.1",
6363
"piscina": "^5.1.4",
64-
"preact": "^10.28.0",
64+
"preact": "^11.0.0-beta.0",
6565
"preact-render-to-string": "^6.6.3",
6666
"reading-time": "^1.5.0",
6767
"recma-jsx": "^1.0.1",

src/generators/ast-js/index.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ export default {
5656
* @param {Partial<GeneratorOptions>} options
5757
* @returns {AsyncGenerator<Output>}
5858
*/
59-
async *generate(_, { input = [], worker }) {
60-
const source = globSync(input).filter(path => extname(path) === '.js');
59+
async *generate(_, { input = [], ignore, worker }) {
60+
const files = globSync(input, { ignore }).filter(p => extname(p) === '.js');
6161

6262
// Parse the Javascript sources into ASTs in parallel using worker threads
6363
// source is both the items list and the fullInput since we use sliceInput
64-
for await (const chunkResult of worker.stream(source, source)) {
64+
for await (const chunkResult of worker.stream(files, files)) {
6565
yield chunkResult;
6666
}
6767
},

src/generators/ast/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export default {
6161
* @param {Partial<GeneratorOptions>} options
6262
* @returns {AsyncGenerator<Output>}
6363
*/
64-
async *generate(_, { input = [], worker }) {
65-
const files = globSync(input).filter(path => extname(path) === '.md');
64+
async *generate(_, { input = [], ignore, worker }) {
65+
const files = globSync(input, { ignore }).filter(p => extname(p) === '.md');
6666

6767
// Parse markdown files in parallel using worker threads
6868
for await (const chunkResult of worker.stream(files, files)) {

src/generators/jsx-ast/utils/getSortedHeadNodes.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ const headingSortFn = (a, b) => {
3333
* @returns {Array<ApiDocMetadataEntry>}
3434
*/
3535
export const getSortedHeadNodes = entries =>
36-
entries.filter(node => node.heading.depth === 1).sort(headingSortFn);
36+
entries.filter(node => node.heading.depth === 1).toSorted(headingSortFn);

src/generators/legacy-html/index.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ export default {
113113

114114
const headNodes = input
115115
.filter(node => node.heading.depth === 1)
116-
.sort((a, b) => a.heading.data.name.localeCompare(b.heading.data.name));
116+
.toSorted((a, b) =>
117+
a.heading.data.name.localeCompare(b.heading.data.name)
118+
);
117119

118120
const indexOfFiles = index
119121
? index.map(({ api, section }) => ({ api, heading: getHeading(section) }))

src/generators/legacy-json-all/index.mjs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default {
2929
* @param {Partial<GeneratorOptions>} options
3030
* @returns {Promise<Output>}
3131
*/
32-
async generate(input, { output }) {
32+
async generate(input, { output, index }) {
3333
/**
3434
* The consolidated output object that will contain
3535
* combined data from all sections in the input.
@@ -49,8 +49,26 @@ export default {
4949
*/
5050
const propertiesToCopy = Object.keys(generatedValue);
5151

52+
// Create a map of api name to index position for sorting
53+
const indexOrder = new Map(
54+
index?.map(({ api }, position) => [`doc/api/${api}.md`, position]) ?? []
55+
);
56+
57+
// Sort input by index order (documents not in index go to the end)
58+
const sortedInput = input.toSorted((a, b) => {
59+
const aOrder = indexOrder.get(a.source) ?? Infinity;
60+
const bOrder = indexOrder.get(b.source) ?? Infinity;
61+
62+
return aOrder - bOrder;
63+
});
64+
5265
// Aggregate all sections into the output
53-
for (const section of input) {
66+
for (const section of sortedInput) {
67+
// Skip index.json - it has no useful content, just navigation
68+
if (section.api === 'index') {
69+
continue;
70+
}
71+
5472
for (const property of propertiesToCopy) {
5573
const items = section[property];
5674

src/generators/legacy-json/utils/buildSection.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ export const createSectionBuilder = () => {
4545
removed_in = [],
4646
changes,
4747
}) => {
48-
const meta = { changes };
48+
const meta = {};
4949

5050
if (added_in?.length) {
5151
meta.added = enforceArray(added_in);
5252
}
5353

54+
meta.changes = changes;
55+
5456
if (n_api_version?.length) {
5557
meta.napiVersion = enforceArray(n_api_version);
5658
}
@@ -81,8 +83,8 @@ export const createSectionBuilder = () => {
8183
const section = {
8284
textRaw: transformNodesToString(head.children),
8385
name: head.data.name,
84-
type: head.data.type,
8586
introduced_in: entry.introduced_in,
87+
type: head.data.type,
8688
};
8789

8890
const meta = createMeta(entry);
@@ -135,8 +137,11 @@ export const createSectionBuilder = () => {
135137
* @param {import('../../types.d.ts').NodeWithData} heading - The heading node of the section.
136138
*/
137139
const addAdditionalMetadata = (section, parent, heading) => {
138-
if (!section.type) {
140+
if (!section.type || section.type === 'module') {
139141
section.name = section.textRaw.toLowerCase().trim().replace(/\s+/g, '_');
142+
}
143+
144+
if (!section.type) {
140145
section.displayName = heading.data.name;
141146
section.type = parent.type === 'misc' ? 'misc' : 'module';
142147
}

src/generators/types.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ declare global {
3737
// be a glob when passed to a generator.
3838
input: string | string[];
3939

40+
// The path or glob patterns used to ignore files from the input source files.
41+
ignore?: string | string[];
42+
4043
// The path used to output generated files, this is to be considered
4144
// the base path that any generator will use for generating files
4245
// This parameter accepts globs but when passed to generators will contain

0 commit comments

Comments
 (0)