Skip to content

Commit a8aacc8

Browse files
authored
meta: switch to minify-html; fixed test glob on package.json; removed console.log (#602)
* meta: switch to minify-htm; fixed test glob on package.json; removed console.log * chore: use terser * chore: use @minify-html/wasm * chore: address copilot warn
1 parent 471bea6 commit a8aacc8

File tree

9 files changed

+64
-227
lines changed

9 files changed

+64
-227
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ updates:
6262
- 'recma-*'
6363
compiling:
6464
patterns:
65-
- '@swc/html'
65+
- '@minify-html/wasm'
6666
- '@rollup/*'
6767
- 'rolldown'
6868
- 'lightningcss'

npm-shrinkwrap.json

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

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
"format": "prettier .",
1111
"format:write": "prettier --write .",
1212
"format:check": "prettier --check .",
13-
"test": "node --test --experimental-test-module-mocks",
14-
"test:coverage": "c8 npm test",
15-
"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",
16-
"test:update-snapshots": "node --test --experimental-test-module-mocks --test-update-snapshots",
17-
"test:watch": "node --test --experimental-test-module-mocks --watch",
13+
"test": "node --test --experimental-test-module-mocks \"src/**/*.test.mjs\"",
14+
"test:coverage": "c8 node --test --experimental-test-module-mocks \"src/**/*.test.mjs\"",
15+
"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",
16+
"test:update-snapshots": "node --test --experimental-test-module-mocks --test-update-snapshots \"src/**/*.test.mjs\"",
17+
"test:watch": "node --test --experimental-test-module-mocks --watch \"src/**/*.test.mjs\"",
1818
"prepare": "husky || exit 0",
1919
"run": "node bin/cli.mjs",
2020
"watch": "node --watch bin/cli.mjs"
@@ -42,12 +42,12 @@
4242
"dependencies": {
4343
"@actions/core": "^3.0.0",
4444
"@heroicons/react": "^2.2.0",
45+
"@minify-html/wasm": "^0.18.1",
4546
"@node-core/rehype-shiki": "^1.4.0",
4647
"@node-core/ui-components": "^1.6.0",
4748
"@orama/orama": "^3.1.18",
4849
"@orama/ui": "^1.5.4",
4950
"@rollup/plugin-virtual": "^3.0.2",
50-
"@swc/html": "^1.15.11",
5151
"acorn": "^8.15.0",
5252
"commander": "^14.0.2",
5353
"dedent": "^1.7.1",

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import { readFile, writeFile } from 'node:fs/promises';
44
import { join } from 'node:path';
55

6-
import { minify } from '@swc/html';
7-
86
import getConfig from '../../utils/configuration/index.mjs';
7+
import { minifyHTML } from '../../utils/html-minifier.mjs';
98
import { getRemarkRehype } from '../../utils/remark.mjs';
109
import legacyHtml from '../legacy-html/index.mjs';
1110
import { replaceTemplateValues } from '../legacy-html/utils/replaceTemplateValues.mjs';
@@ -86,7 +85,7 @@ export default {
8685
});
8786

8887
if (config.minify) {
89-
({ code: result } = await minify(result));
88+
result = Buffer.from(await minifyHTML(result));
9089
}
9190

9291
if (config.output) {

src/generators/legacy-html/index.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
import { readFile, writeFile, mkdir } from 'node:fs/promises';
44
import { basename, join } from 'node:path';
55

6-
import { minify } from '@swc/html';
7-
86
import buildContent from './utils/buildContent.mjs';
97
import { replaceTemplateValues } from './utils/replaceTemplateValues.mjs';
108
import { safeCopy } from './utils/safeCopy.mjs';
119
import tableOfContents from './utils/tableOfContents.mjs';
1210
import getConfig from '../../utils/configuration/index.mjs';
1311
import { groupNodesByModule } from '../../utils/generators.mjs';
12+
import { minifyHTML } from '../../utils/html-minifier.mjs';
1413
import { getRemarkRehypeWithShiki } from '../../utils/remark.mjs';
1514

1615
/**
@@ -159,7 +158,7 @@ export default {
159158
let result = replaceTemplateValues(apiTemplate, template, config);
160159

161160
if (config.minify) {
162-
({ code: result } = await minify(result));
161+
result = Buffer.from(await minifyHTML(result));
163162
}
164163

165164
await writeFile(join(config.output, `${template.api}.html`), result);

src/generators/web/utils/processing.mjs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { randomUUID } from 'node:crypto';
22

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

7-
import { SPECULATION_RULES } from '../constants.mjs';
86
import bundleCode from './bundle.mjs';
97
import { createChunkedRequire } from './chunks.mjs';
8+
import { minifyHTML } from '../../../utils/html-minifier.mjs';
9+
import { SPECULATION_RULES } from '../constants.mjs';
1010

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

111111
// Step 3: Create final HTML (could be parallelized in workers)
112-
const results = entries.map(({ data: { api, heading } }) => {
113-
const fileName = `${api}.js`;
114-
const title = `${heading.data.name} | ${titleSuffix}`;
115-
116-
// Replace template placeholders with actual content
117-
const renderedHtml = template
118-
.replace('{{title}}', title)
119-
.replace('{{dehydrated}}', serverBundle.pages.get(fileName) ?? '')
120-
.replace('{{importMap}}', clientBundle.importMap ?? '')
121-
.replace('{{entrypoint}}', `./${fileName}?${randomUUID()}`)
122-
.replace('{{speculationRules}}', SPECULATION_RULES)
123-
.replace('{{ogTitle}}', title);
124-
125-
// Minify HTML (input must be a Buffer)
126-
const { code: html } = minifySync(renderedHtml);
127-
128-
return { html, api };
129-
});
112+
const results = await Promise.all(
113+
entries.map(async ({ data: { api, heading } }) => {
114+
const fileName = `${api}.js`;
115+
const title = `${heading.data.name} | ${titleSuffix}`;
116+
117+
// Replace template placeholders with actual content
118+
const renderedHtml = template
119+
.replace('{{title}}', title)
120+
.replace('{{dehydrated}}', serverBundle.pages.get(fileName) ?? '')
121+
.replace('{{importMap}}', clientBundle.importMap ?? '')
122+
.replace('{{entrypoint}}', `./${fileName}?${randomUUID()}`)
123+
.replace('{{speculationRules}}', SPECULATION_RULES)
124+
.replace('{{ogTitle}}', title);
125+
126+
const minifiedHtml = await minifyHTML(renderedHtml);
127+
const html = Buffer.from(minifiedHtml);
128+
129+
return { html, api };
130+
})
131+
);
130132

131133
const { code: minifiedCSS } = transform({
132134
code: Buffer.from(`${serverBundle.css}\n${clientBundle.css}`),

src/utils/configuration/__tests__/index.test.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ describe('config.mjs', () => {
137137
threads: 2,
138138
});
139139

140-
console.log(config);
141-
142140
assert.strictEqual(config.global.input, 'custom-src/');
143141
assert.strictEqual(config.global.output, 'custom-dist/');
144142
assert.strictEqual(config.threads, 2);

0 commit comments

Comments
 (0)