Skip to content

Commit a8c99d9

Browse files
targosBethGriggs
authored andcommitted
tools: update doc generator dependencies
PR-URL: #40042 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 98d42fa commit a8c99d9

File tree

10 files changed

+1612
-1060
lines changed

10 files changed

+1612
-1060
lines changed

test/doctool/test-doctool-html.mjs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ import * as fixtures from '../common/fixtures.mjs';
33

44
import assert from 'assert';
55
import { readFileSync } from 'fs';
6-
import { createRequire } from 'module';
76

87
import * as html from '../../tools/doc/html.mjs';
98
import { replaceLinks } from '../../tools/doc/markdown.mjs';
10-
11-
const require = createRequire(new URL('../../tools/doc/', import.meta.url));
12-
const unified = require('unified');
13-
const markdown = require('remark-parse');
14-
const remark2rehype = require('remark-rehype');
15-
const raw = require('rehype-raw');
16-
const htmlStringify = require('rehype-stringify');
9+
import {
10+
rehypeRaw,
11+
rehypeStringify,
12+
remarkParse,
13+
remarkRehype,
14+
unified,
15+
} from '../../tools/doc/deps.mjs';
1716

1817
// Test links mapper is an object of the following structure:
1918
// {
@@ -31,14 +30,14 @@ const testLinksMapper = {
3130
function toHTML({ input, filename, nodeVersion, versions }) {
3231
const content = unified()
3332
.use(replaceLinks, { filename, linksMapper: testLinksMapper })
34-
.use(markdown)
33+
.use(remarkParse)
3534
.use(html.firstHeader)
3635
.use(html.preprocessText, { nodeVersion })
3736
.use(html.preprocessElements, { filename })
3837
.use(html.buildToc, { filename, apilinks: {} })
39-
.use(remark2rehype, { allowDangerousHtml: true })
40-
.use(raw)
41-
.use(htmlStringify)
38+
.use(remarkRehype, { allowDangerousHtml: true })
39+
.use(rehypeRaw)
40+
.use(rehypeStringify)
4241
.processSync(input);
4342

4443
return html.toHTML({ input, content, filename, nodeVersion, versions });

test/doctool/test-doctool-json.mjs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ import * as fixtures from '../common/fixtures.mjs';
33

44
import assert from 'assert';
55
import fs from 'fs';
6-
import { createRequire } from 'module';
76

87
import * as json from '../../tools/doc/json.mjs';
9-
10-
const require = createRequire(new URL('../../tools/doc/', import.meta.url));
11-
const unified = require('unified');
12-
const markdown = require('remark-parse');
8+
import {
9+
remarkParse,
10+
unified,
11+
} from '../../tools/doc/deps.mjs';
1312

1413
function toJSON(input, filename, cb) {
1514
function nullCompiler() {
1615
this.Compiler = (tree) => tree;
1716
}
1817

1918
unified()
20-
.use(markdown)
19+
.use(remarkParse)
2120
.use(json.jsonAPI, { filename })
2221
.use(nullCompiler)
2322
.process(input, cb);

tools/doc/addon-verify.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { mkdir, writeFile } from 'fs/promises';
99
import gfm from 'remark-gfm';
1010
import remarkParse from 'remark-parse';
1111
import { toVFile } from 'to-vfile';
12-
import unified from 'unified';
12+
import { unified } from 'unified';
1313

1414
const rootDir = new URL('../../', import.meta.url);
1515
const doc = new URL('./doc/api/addons.md', rootDir);

tools/doc/deps.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Re-exporting dependencies for tests in test/doctool.
2+
3+
export { default as rehypeRaw } from 'rehype-raw';
4+
export { default as rehypeStringify } from 'rehype-stringify';
5+
export { default as remarkParse } from 'remark-parse';
6+
export { default as remarkRehype } from 'remark-rehype';
7+
export { unified } from 'unified';

tools/doc/generate.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import gfm from 'remark-gfm';
2828
import markdown from 'remark-parse';
2929
import remark2rehype from 'remark-rehype';
3030
import frontmatter from 'remark-frontmatter';
31-
import unified from 'unified';
31+
import { unified } from 'unified';
3232

3333
import * as html from './html.mjs';
3434
import * as json from './json.mjs';

tools/doc/html.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import htmlStringify from 'rehype-stringify';
2828
import gfm from 'remark-gfm';
2929
import markdown from 'remark-parse';
3030
import remark2rehype from 'remark-rehype';
31-
import unified from 'unified';
31+
import { unified } from 'unified';
3232
import { visit } from 'unist-util-visit';
3333

3434
import * as common from './common.mjs';
@@ -395,7 +395,7 @@ export function buildToc({ filename, apilinks }) {
395395

396396
depth = node.depth;
397397
const realFilename = path.basename(filename, '.md');
398-
const headingText = file.contents.slice(
398+
const headingText = file.value.slice(
399399
node.children[0].position.start.offset,
400400
node.position.end.offset).trim();
401401
const id = getId(`${realFilename}_${headingText}`, idCounters);

tools/doc/json.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
import html from 'remark-html';
23-
import unified from 'unified';
23+
import { unified } from 'unified';
2424
import { selectAll } from 'unist-util-select';
2525

2626
import * as common from './common.mjs';
@@ -376,7 +376,7 @@ function parseListItem(item, file) {
376376

377377
current.textRaw = item.children.filter((node) => node.type !== 'list')
378378
.map((node) => (
379-
file.contents.slice(node.position.start.offset, node.position.end.offset))
379+
file.value.slice(node.position.start.offset, node.position.end.offset))
380380
)
381381
.join('').replace(/\s+/g, ' ').replace(/<!--.*?-->/sg, '');
382382
let text = current.textRaw;
@@ -491,8 +491,8 @@ function newSection(header, file) {
491491
function textJoin(nodes, file) {
492492
return nodes.map((node) => {
493493
if (node.type === 'linkReference') {
494-
return file.contents.slice(node.position.start.offset,
495-
node.position.end.offset);
494+
return file.value.slice(node.position.start.offset,
495+
node.position.end.offset);
496496
} else if (node.type === 'inlineCode') {
497497
return `\`${node.value}\``;
498498
} else if (node.type === 'strong') {

0 commit comments

Comments
 (0)