-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathgenerate.mjs
More file actions
48 lines (39 loc) · 1.29 KB
/
generate.mjs
File metadata and controls
48 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import buildContent from './utils/buildContent.mjs';
import { getSortedHeadNodes } from './utils/getSortedHeadNodes.mjs';
import { groupNodesByModule } from '../../utils/generators.mjs';
/**
* Process a chunk of items in a worker thread.
* Transforms metadata entries into JSX AST nodes.
*
* Each item is a SlicedModuleInput containing the head node
* and all entries for that module - no need to recompute grouping.
*
* @type {import('./types').Generator['processChunk']}
*/
export async function processChunk(slicedInput, itemIndices) {
const results = [];
for (const idx of itemIndices) {
const { head, entries } = slicedInput[idx];
const content = await buildContent(entries, head);
results.push(content);
}
return results;
}
/**
* Generates a JSX AST
*
* @type {import('./types').Generator['generate']}
*/
export async function* generate(input, worker) {
const groupedModules = groupNodesByModule(input);
const headNodes = getSortedHeadNodes(input);
// Create sliced input: each item contains head + its module's entries
// This avoids sending all 4700+ entries to every worker
const entries = headNodes.map(head => ({
head,
entries: groupedModules.get(head.api),
}));
for await (const chunkResult of worker.stream(entries)) {
yield chunkResult;
}
}