Skip to content

Commit a8c99d9

Browse files
targosBethGriggs
authored andcommittedSep 21, 2021
tools: update doc generator dependencies
PR-URL: #40042 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 98d42fa commit a8c99d9

10 files changed

+1612
-1060
lines changed
 

‎test/doctool/test-doctool-html.mjs

+11-12
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

+5-6
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

+1-1
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

+7
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

+1-1
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

+2-2
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

+4-4
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') {

‎tools/doc/package-lock.json

+1,566-1,019
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tools/doc/package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
"node": ">=14.8.0"
88
},
99
"devDependencies": {
10-
"highlight.js": "11.0.1",
11-
"js-yaml": "4.1.0",
12-
"rehype-raw": "5.1.0",
13-
"rehype-stringify": "8.0.0",
14-
"remark-frontmatter": "^3.0.0",
15-
"remark-gfm": "^1.0.0",
16-
"remark-html": "13.0.2",
17-
"remark-parse": "^9.0.0",
18-
"remark-rehype": "8.1.0",
19-
"to-vfile": "7.1.0",
20-
"unified": "9.2.1",
21-
"unist-util-select": "4.0.0",
22-
"unist-util-visit": "3.1.0"
10+
"highlight.js": "^11.2.0",
11+
"js-yaml": "^4.1.0",
12+
"rehype-raw": "^6.1.0",
13+
"rehype-stringify": "^9.0.2",
14+
"remark-frontmatter": "^4.0.0",
15+
"remark-gfm": "^2.0.0",
16+
"remark-html": "^14.0.1",
17+
"remark-parse": "^10.0.0",
18+
"remark-rehype": "^9.0.0",
19+
"to-vfile": "^7.2.2",
20+
"unified": "^10.1.0",
21+
"unist-util-select": "^4.0.0",
22+
"unist-util-visit": "^4.0.0"
2323
},
2424
"bin": {
2525
"node-doc-generator": "generate.js"

‎tools/doc/stability.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import htmlStringify from 'rehype-stringify';
77
import gfm from 'remark-gfm';
88
import markdown from 'remark-parse';
99
import remark2rehype from 'remark-rehype';
10-
import unified from 'unified';
10+
import { unified } from 'unified';
1111
import { visit } from 'unist-util-visit';
1212

1313
const source = new URL('../../out/doc/api/', import.meta.url);
@@ -63,7 +63,7 @@ function createHTML(md) {
6363
.use(processStability)
6464
.processSync(md);
6565

66-
return file.contents.trim();
66+
return file.value.trim();
6767
}
6868

6969
function processStability() {

0 commit comments

Comments
 (0)
Please sign in to comment.