From 0c67d326dcf36bb33a9a15000b2fe673a88b04fe Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Wed, 25 Jul 2018 14:58:41 -0700 Subject: [PATCH] tools: convert addon-verify to remark This is the last use of the remark *module*. tools/remark-cli and tools/remark-preset-lint-node remain. PR-URL: https://github.com/nodejs/node/pull/21978 Reviewed-By: Anna Henningsen Reviewed-By: Gireesh Punathil Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- tools/doc/addon-verify.js | 30 ++++++++++++++++++++---------- tools/doc/package-lock.json | 14 +++++++++----- tools/doc/package.json | 2 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/tools/doc/addon-verify.js b/tools/doc/addon-verify.js index a3d1beb4b8e12e..ae6a08b2cc6475 100644 --- a/tools/doc/addon-verify.js +++ b/tools/doc/addon-verify.js @@ -1,28 +1,38 @@ 'use strict'; -const { mkdir, readFileSync, writeFile } = require('fs'); +// doc/api/addons.md has a bunch of code. Extract it for verification +// that the C++ code compiles and the js code runs. +// Add .gyp files which will be used to compile the C++ code. +// Modify the require paths in the js code to pull from the build tree. +// Triggered from the build-addons target in the Makefile and vcbuild.bat. + +const { mkdir, writeFile } = require('fs'); const { resolve } = require('path'); -const { lexer } = require('marked'); +const vfile = require('to-vfile'); +const unified = require('unified'); +const remarkParse = require('remark-parse'); const rootDir = resolve(__dirname, '..', '..'); const doc = resolve(rootDir, 'doc', 'api', 'addons.md'); const verifyDir = resolve(rootDir, 'test', 'addons'); -const tokens = lexer(readFileSync(doc, 'utf8')); +const file = vfile.readSync(doc, 'utf8'); +const tree = unified().use(remarkParse).parse(file); const addons = {}; let id = 0; let currentHeader; const validNames = /^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/; -tokens.forEach(({ type, text }) => { - if (type === 'heading') { - currentHeader = text; +tree.children.forEach((node) => { + if (node.type === 'heading') { + currentHeader = file.contents.slice( + node.children[0].position.start.offset, + node.position.end.offset); addons[currentHeader] = { files: {} }; - } - if (type === 'code') { - const match = text.match(validNames); + } else if (node.type === 'code') { + const match = node.value.match(validNames); if (match !== null) { - addons[currentHeader].files[match[1]] = text; + addons[currentHeader].files[match[1]] = node.value; } } }); diff --git a/tools/doc/package-lock.json b/tools/doc/package-lock.json index 8e7a886fe1255c..c688e60c1577c8 100644 --- a/tools/doc/package-lock.json +++ b/tools/doc/package-lock.json @@ -339,11 +339,6 @@ "resolved": "https://registry.npmjs.org/markdown-table/-/markdown-table-0.4.0.tgz", "integrity": "sha1-iQwsGzv+g/sA5BKbjkz+ZFJw+dE=" }, - "marked": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/marked/-/marked-0.4.0.tgz", - "integrity": "sha512-tMsdNBgOsrUophCAFQl0XPe6Zqk/uy9gnue+jIIKhykO51hxyu6uNx7zBPy0+y/WKYVZZMspV9YeXLNdKk+iYw==" - }, "mdast-util-definitions": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/mdast-util-definitions/-/mdast-util-definitions-1.2.2.tgz", @@ -591,6 +586,15 @@ "is-hexadecimal": "^1.0.0" } }, + "to-vfile": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/to-vfile/-/to-vfile-5.0.0.tgz", + "integrity": "sha512-sUeBtb4i09pNIzPtl/PMW20Xfe/NK82oV0IehtmoX/+PhIdvc6JHMRnmC4fjCIcy0LOwcNqB8iRMtTBzXHVbng==", + "requires": { + "is-buffer": "^2.0.0", + "vfile": "^3.0.0" + } + }, "trim": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/trim/-/trim-0.0.1.tgz", diff --git a/tools/doc/package.json b/tools/doc/package.json index 8c573ec458cb07..41ae87889d36e4 100644 --- a/tools/doc/package.json +++ b/tools/doc/package.json @@ -7,12 +7,12 @@ "node": ">=6" }, "dependencies": { - "marked": "^0.4.0", "rehype-raw": "^2.0.0", "rehype-stringify": "^3.0.0", "remark-html": "^7.0.0", "remark-parse": "^5.0.0", "remark-rehype": "^3.0.0", + "to-vfile": "^5.0.0", "unified": "^7.0.0", "unist-util-find": "^1.0.1", "unist-util-select": "^1.5.0",