Skip to content

Commit 4056fed

Browse files
authored
refactor: call a page with parts a composed page, and test it where it lives
The code and types already called it a composed page, while the docs, comments and tests said a page made of other pages. They all say composed page now. html-all no longer adds all.html at the end when no manifest came, as jsx-ast always sends one, and each page it lists arrives. html's test of the bundles' timing no longer gives it all.html, whose place html-all's tests check, the composed page's program test only checks what it imports, as html's tests render one, and html's tests build all.html's metadata with createSyntheticHead. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8af3b58 commit 4056fed

11 files changed

Lines changed: 24 additions & 78 deletions

File tree

‎.changeset/html-all.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
'@node-core/doc-kit': minor
55
---
66

7-
`all.html` moves out of the `html` generator into a new Node.js generator, `html-all` (`@node-core/doc-kit`), and `html`'s `generateAllPage` option is removed. `html-all` is spliced between `jsx-ast` and `html`, and adds `all.html`, every module page's content on one page, as a page made of theirs. `html` renders such a page, given with `parts`, the pages it is made of, from their compiled content, one part at a time rather than building every part's elements first. Builds that want `all.html` add the `html-all` target.
7+
`all.html` moves out of the `html` generator into a new Node.js generator, `html-all` (`@node-core/doc-kit`), and `html`'s `generateAllPage` option is removed. `html-all` is spliced between `jsx-ast` and `html`, and adds `all.html`, every module page's content on one page, as a composed page. `html` renders a composed page, given with `parts`, from its parts' compiled content, one part at a time rather than building every part's elements first. Builds that want `all.html` add the `html-all` target.

‎packages/node/src/html-all/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The `html-all` generator adds `all.html`, every module page's content on one
44
page, to the pages the [`html`](./html.md) generator renders. It builds nothing
55
itself: it is spliced between `jsx-ast` and `html`, passes the pages on, adds
66
`all.html`'s metadata to the manifest, and once every module page has passed,
7-
adds a page made of theirs. `html` assembles it from their compiled content,
7+
adds a composed page of them. `html` assembles it from their compiled content,
88
so no module is built twice.
99

1010
The module pages are its parts, in the order the sidebar lists them; the

‎packages/node/src/html-all/generate.mjs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,4 @@ export async function* generate(input) {
8787

8888
yield pages;
8989
}
90-
91-
// Without a manifest, once every page has passed
92-
if (!added) {
93-
yield [buildAllPage(parts)];
94-
}
9590
}

‎packages/node/src/html-all/index.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { generate } from './generate.mjs';
55
/**
66
* Adds `all.html`, every module page's content on one page, to the pages the
77
* `html` generator renders. It builds nothing itself: it passes `jsx-ast`'s
8-
* pages on to `html`, and, once every module page has passed, a page made of
9-
* theirs, which `html` assembles from their compiled content.
8+
* pages on to `html`, and, once every module page has passed, a composed page
9+
* of them, which `html` assembles from their compiled content.
1010
*
1111
* @type {import('./types').Generator}
1212
*/

‎packages/react/src/html/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ the pages one at a time as they are compiled, so memory scales with the largest
1515
page rather than with the site. With one thread, each step waits for the one
1616
before it to finish.
1717

18-
A page can be made of other pages' content: an input item with `parts`, the
19-
`api`s of the pages it is made of, which come before it in the input, and its
18+
A page can be a composed page: an input item with `parts`, the `api`s of the
19+
pages whose content it shows, which come before it in the input, and its
2020
`headings`. Its program imports theirs, so they are not built again, and it is
2121
rendered first, as it takes the longest. Node.js's `html-all` generator
2222
(`@node-core/doc-kit`) adds `all.html` this way.
@@ -489,7 +489,7 @@ export default ({ metadata }) => (
489489
- `headings` {Array} Pre-computed table of contents heading entries.
490490
- `readingTime` {string|undefined} Estimated reading time (e.g. `'5 min read'`).
491491
Only present when the `jsx-ast` generator's `showReadingTime` option is
492-
enabled. A page made of others has none.
492+
enabled. A composed page has none.
493493
- `children` {ComponentChildren} Processed page content.
494494
495495
The `Layout` component receives the props above. Custom Layout components can use

‎packages/react/src/html/__tests__/generate.test.mjs‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { jsx, toJs } from 'estree-util-to-js';
1414

1515
import buildContent from '../../jsx-ast/utils/buildContent.mjs';
1616
import { buildNotFoundPage } from '../../jsx-ast/utils/synthetic/404.mjs';
17+
import { createSyntheticHead } from '../../jsx-ast/utils/synthetic/synthetic.mjs';
1718
import { generate as sectionPages } from '../../section-pages/generate.mjs';
1819
import { compile, createViteBundler } from '../bundlers/vite.mjs';
1920
import { FONTS } from '../constants.mjs';
@@ -30,24 +31,13 @@ async function* streamInOneBatch(items) {
3031
}
3132

3233
/**
33-
* A page made of the given pages' content, in that order, as Node.js's
34+
* A composed page of the given pages' content, in that order, as Node.js's
3435
* `html-all` generator gives `all.html`.
3536
*
3637
* @param {Array<{ data: { api: string }, headings: Array<object> }>} pages
3738
*/
3839
const createAllPage = pages => ({
39-
data: {
40-
api: 'all',
41-
path: '/all',
42-
basename: 'all',
43-
synthetic: true,
44-
heading: {
45-
type: 'heading',
46-
depth: 1,
47-
children: [{ type: 'text', value: 'All' }],
48-
data: { name: 'All', text: 'All', slug: 'all' },
49-
},
50-
},
40+
data: createSyntheticHead('all', 'All'),
5141
headings: pages.flatMap(({ headings }) => headings),
5242
parts: pages.map(({ data }) => data.api),
5343
});
@@ -262,7 +252,7 @@ describe('web generate', () => {
262252
}
263253
});
264254

265-
it('assembles a page made of other pages from their content', async context => {
255+
it("assembles a composed page from its parts' content", async context => {
266256
const { output } = await createTestConfiguration(context);
267257

268258
const entries = [
@@ -290,7 +280,7 @@ describe('web generate', () => {
290280
assert.doesNotMatch(html, /View As/);
291281
});
292282

293-
it('numbers the ids of a page made of others across its parts', async context => {
283+
it('numbers the ids of a composed page across its parts', async context => {
294284
const { output } = await createTestConfiguration(context);
295285

296286
// Each module has code tabs, whose elements take ids
@@ -582,19 +572,17 @@ describe('web generate', () => {
582572
// The bundles are built without waiting for the pages still to come
583573
await bundled.promise;
584574

585-
yield [fs, all];
575+
yield [fs];
586576
yield [index];
587577
}
588578

589579
await generatePages(input());
590580

591-
// The page made of others comes right after its last part
592581
assert.deepStrictEqual(calls, [
593582
'zlib.jsx',
594583
'server',
595584
'client',
596585
'fs.jsx',
597-
'all.jsx',
598586
'index.jsx',
599587
]);
600588
}

‎packages/react/src/html/generate.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const htmlLogger = logger.child('html');
2727
* page's program is compiled to a plain module as it arrives, the component
2828
* library and the client assets are bundled once every page's metadata is
2929
* known, and the worker pool renders the pages as they are compiled, one in
30-
* memory per worker. A page made of other pages' content (with `parts`, which
30+
* memory per worker. A composed page (with `parts`, the pages it shows, which
3131
* come before it) imports their compiled programs, and is rendered first. With
3232
* one thread, the input arrives whole.
3333
*
@@ -221,7 +221,7 @@ const buildSite = async (input, options) => {
221221

222222
compiled.push(task);
223223

224-
// A page made of others' content takes by far the longest to render
224+
// A composed page takes by far the longest to render
225225
if ('parts' in item) {
226226
rendering.prepend([task]);
227227
} else {

‎packages/react/src/html/index.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import { processChunk } from './utils/render.mjs';
1717
* known, the configured bundler builds the component library and the client
1818
* assets once each, and the worker pool renders, templates, minifies and writes
1919
* the pages one at a time as they are compiled, so memory scales with the
20-
* largest page rather than with the site. A page made of other pages' content,
21-
* such as Node.js's `all.html` (see its `html-all` generator), is assembled from
22-
* their compiled content instead of being built again.
20+
* largest page rather than with the site. A composed page, such as Node.js's
21+
* `all.html` (see its `html-all` generator), is assembled from its parts'
22+
* compiled content instead of being built again.
2323
*
2424
* This terminal generator writes to the output directory and does not return
2525
* an in-memory copy.
Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import assert from 'node:assert/strict';
2-
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
3-
import { tmpdir } from 'node:os';
4-
import { join } from 'node:path';
52
import { describe, it } from 'node:test';
6-
import { pathToFileURL } from 'node:url';
73

84
import { setConfig } from '@doc-kit/core/utils/configuration/index.mjs';
95

10-
import { compile } from '../../bundlers/vite.mjs';
11-
import createProgramBuilder, { moduleFileName } from '../generate.mjs';
6+
import createProgramBuilder from '../generate.mjs';
127

138
describe('buildPageProgram', () => {
14-
it('imports no component into a composed page, whatever the components are named', async context => {
9+
it('imports no component into a composed page, whatever the components are named', async () => {
1510
const config = await setConfig({
1611
target: ['html'],
1712
version: 'v22.0.0',
@@ -22,31 +17,8 @@ describe('buildPageProgram', () => {
2217
// Named like the composed page's own wrapper
2318
config.html.components = { ComposedPart: '/components/ComposedPart.jsx' };
2419

25-
const dir = await mkdtemp(join(tmpdir(), 'doc-kit-program-test-'));
26-
context.after(() => rm(dir, { recursive: true, force: true }));
27-
28-
// A stand-in for the built library, which exports every component, and
29-
// the part the page is made of
30-
const library = join(dir, 'library.mjs');
31-
32-
await writeFile(
33-
library,
34-
[
35-
'export const h = (type, props, ...children) => ({ type, props, children });',
36-
'export const Fragment = "Fragment";',
37-
'export const Layout = "Layout";',
38-
'export const renderToStringAsync = async () => "";',
39-
'export const ComposedPart = () => null;',
40-
].join('\n')
41-
);
42-
43-
await writeFile(
44-
join(dir, moduleFileName('fs')),
45-
'export const content = () => "File system";'
46-
);
47-
4820
const { buildPageProgram } = createProgramBuilder();
49-
const libraryURL = pathToFileURL(library).href;
21+
const libraryURL = 'file:///library.mjs';
5022
const program = buildPageProgram(
5123
{ data: { api: 'all' }, headings: [], parts: ['fs'] },
5224
libraryURL
@@ -57,14 +29,5 @@ describe('buildPageProgram', () => {
5729
.find(line => line.includes(JSON.stringify(libraryURL)));
5830

5931
assert.doesNotMatch(imports, /ComposedPart/);
60-
61-
const file = join(dir, moduleFileName('all'));
62-
const code = await compile(program, 'all.jsx');
63-
64-
await writeFile(file, code);
65-
66-
const { content } = await import(pathToFileURL(file).href);
67-
68-
assert.equal(typeof content, 'function');
6932
});
7033
});

‎packages/react/src/jsx-ast/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Each page is emitted as `{ data, headings, readingTime, content }`: the page's
1919
head entry, its table of contents, the optional reading time, and the processed
2020
content serialized to JSX code as one fragment. The page layout is not part of
2121
the content — the `html` generator wraps each page in `<Layout>`, and assembles
22-
pages made of other pages' content, such as Node.js's `all.html`, rather than
22+
composed pages, such as Node.js's `all.html`, from their parts rather than
2323
building them a second time here.
2424

2525
Pages are emitted as they are built, in the order their entries arrived, the

0 commit comments

Comments
 (0)