Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ updates:
- 'recma-*'
compiling:
patterns:
- '@swc/html'
- '@minify-html/wasm'
- '@rollup/*'
- 'rolldown'
- 'lightningcss'
Expand Down
198 changes: 7 additions & 191 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"format": "prettier .",
"format:write": "prettier --write .",
"format:check": "prettier --check .",
"test": "node --test --experimental-test-module-mocks",
"test:coverage": "c8 npm test",
"test:ci": "c8 --reporter=lcov node --test --experimental-test-module-mocks --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=junit --test-reporter-destination=junit.xml --test-reporter=spec --test-reporter-destination=stdout",
"test:update-snapshots": "node --test --experimental-test-module-mocks --test-update-snapshots",
"test:watch": "node --test --experimental-test-module-mocks --watch",
"test": "node --test --experimental-test-module-mocks \"src/**/*.test.mjs\"",
"test:coverage": "c8 node --test --experimental-test-module-mocks \"src/**/*.test.mjs\"",
"test:ci": "c8 --reporter=lcov node --test --experimental-test-module-mocks \"src/**/*.test.mjs\" --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=junit --test-reporter-destination=junit.xml --test-reporter=spec --test-reporter-destination=stdout",
"test:update-snapshots": "node --test --experimental-test-module-mocks --test-update-snapshots \"src/**/*.test.mjs\"",
"test:watch": "node --test --experimental-test-module-mocks --watch \"src/**/*.test.mjs\"",
"prepare": "husky || exit 0",
"run": "node bin/cli.mjs",
"watch": "node --watch bin/cli.mjs"
Expand Down Expand Up @@ -42,12 +42,12 @@
"dependencies": {
"@actions/core": "^3.0.0",
"@heroicons/react": "^2.2.0",
"@minify-html/wasm": "^0.18.1",
"@node-core/rehype-shiki": "^1.4.0",
"@node-core/ui-components": "^1.6.0",
"@orama/orama": "^3.1.18",
"@orama/ui": "^1.5.4",
"@rollup/plugin-virtual": "^3.0.2",
"@swc/html": "^1.15.11",
"acorn": "^8.15.0",
"commander": "^14.0.2",
"dedent": "^1.7.1",
Expand Down
5 changes: 2 additions & 3 deletions src/generators/legacy-html-all/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import { readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

import { minify } from '@swc/html';

import getConfig from '../../utils/configuration/index.mjs';
import { minifyHTML } from '../../utils/html-minifier.mjs';
import { getRemarkRehype } from '../../utils/remark.mjs';
import legacyHtml from '../legacy-html/index.mjs';
import { replaceTemplateValues } from '../legacy-html/utils/replaceTemplateValues.mjs';
Expand Down Expand Up @@ -86,7 +85,7 @@ export default {
});

if (config.minify) {
({ code: result } = await minify(result));
result = Buffer.from(await minifyHTML(result));
}

if (config.output) {
Expand Down
5 changes: 2 additions & 3 deletions src/generators/legacy-html/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import { readFile, writeFile, mkdir } from 'node:fs/promises';
import { basename, join } from 'node:path';

import { minify } from '@swc/html';

import buildContent from './utils/buildContent.mjs';
import { replaceTemplateValues } from './utils/replaceTemplateValues.mjs';
import { safeCopy } from './utils/safeCopy.mjs';
import tableOfContents from './utils/tableOfContents.mjs';
import getConfig from '../../utils/configuration/index.mjs';
import { groupNodesByModule } from '../../utils/generators.mjs';
import { minifyHTML } from '../../utils/html-minifier.mjs';
import { getRemarkRehypeWithShiki } from '../../utils/remark.mjs';

/**
Expand Down Expand Up @@ -159,7 +158,7 @@ export default {
let result = replaceTemplateValues(apiTemplate, template, config);

if (config.minify) {
({ code: result } = await minify(result));
result = Buffer.from(await minifyHTML(result));
}

await writeFile(join(config.output, `${template.api}.html`), result);
Expand Down
42 changes: 22 additions & 20 deletions src/generators/web/utils/processing.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { randomUUID } from 'node:crypto';

import { minifySync } from '@swc/html';
import { jsx, toJs } from 'estree-util-to-js';
import { transform } from 'lightningcss';

import { SPECULATION_RULES } from '../constants.mjs';
import bundleCode from './bundle.mjs';
import { createChunkedRequire } from './chunks.mjs';
import { minifyHTML } from '../../../utils/html-minifier.mjs';
import { SPECULATION_RULES } from '../constants.mjs';

/**
* Converts JSX AST entries to server and client JavaScript code.
Expand Down Expand Up @@ -109,24 +109,26 @@ export async function processJSXEntries(
const titleSuffix = `Node.js v${version.version} Documentation`;

// Step 3: Create final HTML (could be parallelized in workers)
const results = entries.map(({ data: { api, heading } }) => {
const fileName = `${api}.js`;
const title = `${heading.data.name} | ${titleSuffix}`;

// Replace template placeholders with actual content
const renderedHtml = template
.replace('{{title}}', title)
.replace('{{dehydrated}}', serverBundle.pages.get(fileName) ?? '')
.replace('{{importMap}}', clientBundle.importMap ?? '')
.replace('{{entrypoint}}', `./${fileName}?${randomUUID()}`)
.replace('{{speculationRules}}', SPECULATION_RULES)
.replace('{{ogTitle}}', title);

// Minify HTML (input must be a Buffer)
const { code: html } = minifySync(renderedHtml);

return { html, api };
});
const results = await Promise.all(
entries.map(async ({ data: { api, heading } }) => {
const fileName = `${api}.js`;
const title = `${heading.data.name} | ${titleSuffix}`;

// Replace template placeholders with actual content
const renderedHtml = template
.replace('{{title}}', title)
.replace('{{dehydrated}}', serverBundle.pages.get(fileName) ?? '')
.replace('{{importMap}}', clientBundle.importMap ?? '')
.replace('{{entrypoint}}', `./${fileName}?${randomUUID()}`)
.replace('{{speculationRules}}', SPECULATION_RULES)
.replace('{{ogTitle}}', title);

const minifiedHtml = await minifyHTML(renderedHtml);
const html = Buffer.from(minifiedHtml);

return { html, api };
})
);

const { code: minifiedCSS } = transform({
code: Buffer.from(`${serverBundle.css}\n${clientBundle.css}`),
Expand Down
2 changes: 0 additions & 2 deletions src/utils/configuration/__tests__/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ describe('config.mjs', () => {
threads: 2,
});

console.log(config);

assert.strictEqual(config.global.input, 'custom-src/');
assert.strictEqual(config.global.output, 'custom-dist/');
assert.strictEqual(config.threads, 2);
Expand Down
Loading
Loading