node/tools/doc/addon-verify.mjs
dependabot[bot] 9c40cd7a9d
tools: update ESLint to 9.14.0
Bumps the eslint group with 7 updates in the /tools/eslint directory:

| Package | From | To |
| --- | --- | --- |
| [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) | `7.25.2` | `7.26.0` |
| [@babel/eslint-parser](https://github.com/babel/babel/tree/HEAD/eslint/babel-eslint-parser) | `7.25.1` | `7.25.9` |
| [@babel/plugin-syntax-import-attributes](https://github.com/babel/babel/tree/HEAD/packages/babel-plugin-syntax-import-attributes) | `7.25.6` | `7.26.0` |
| [@stylistic/eslint-plugin-js](https://github.com/eslint-stylistic/eslint-stylistic/tree/HEAD/packages/eslint-plugin-js) | `2.8.0` | `2.10.1` |
| [eslint](https://github.com/eslint/eslint) | `9.11.1` | `9.14.0` |
| [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) | `50.3.1` | `50.4.3` |
| [globals](https://github.com/sindresorhus/globals) | `15.10.0` | `15.11.0` |

Updates `@babel/core` from 7.25.2 to 7.26.0
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.26.0/packages/babel-core)

Updates `@babel/eslint-parser` from 7.25.1 to 7.25.9
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.25.9/eslint/babel-eslint-parser)

Updates `@babel/plugin-syntax-import-attributes` from 7.25.6 to 7.26.0
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.26.0/packages/babel-plugin-syntax-import-attributes)

Updates `@stylistic/eslint-plugin-js` from 2.8.0 to 2.10.1
- [Release notes](https://github.com/eslint-stylistic/eslint-stylistic/releases)
- [Changelog](https://github.com/eslint-stylistic/eslint-stylistic/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint-stylistic/eslint-stylistic/commits/v2.10.1/packages/eslint-plugin-js)

Updates `eslint` from 9.11.1 to 9.14.0
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v9.11.1...v9.14.0)

Updates `eslint-plugin-jsdoc` from 50.3.1 to 50.4.3
- [Release notes](https://github.com/gajus/eslint-plugin-jsdoc/releases)
- [Changelog](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/.releaserc)
- [Commits](https://github.com/gajus/eslint-plugin-jsdoc/compare/v50.3.1...v50.4.3)

Updates `globals` from 15.10.0 to 15.11.0
- [Release notes](https://github.com/sindresorhus/globals/releases)
- [Commits](https://github.com/sindresorhus/globals/compare/v15.10.0...v15.11.0)

---
updated-dependencies:
- dependency-name: "@babel/core"
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: eslint
- dependency-name: "@babel/eslint-parser"
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: eslint
- dependency-name: "@babel/plugin-syntax-import-attributes"
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: eslint
- dependency-name: "@stylistic/eslint-plugin-js"
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: eslint
- dependency-name: eslint
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: eslint
- dependency-name: eslint-plugin-jsdoc
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: eslint
- dependency-name: globals
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: eslint
...

Signed-off-by: dependabot[bot] <support@github.com>
PR-URL: https://github.com/nodejs/node/pull/55689
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-11-06 00:37:39 +01:00

94 lines
2.6 KiB
JavaScript

// 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.
import { mkdir, writeFile } from 'fs/promises';
import gfm from 'remark-gfm';
import remarkParse from 'remark-parse';
import { readSync } from 'to-vfile';
import { unified } from 'unified';
const rootDir = new URL('../../', import.meta.url);
const doc = new URL('./doc/api/addons.md', rootDir);
const verifyDir = new URL('./test/addons/', rootDir);
const file = readSync(doc, 'utf8');
const tree = unified().use(remarkParse).use(gfm).parse(file);
const addons = {};
let id = 0;
let currentHeader;
const validNames = /^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/;
tree.children.forEach((node) => {
if (node.type === 'heading') {
currentHeader = file.value.slice(
node.children[0].position.start.offset,
node.position.end.offset);
addons[currentHeader] = { files: {} };
} else if (node.type === 'code') {
const match = node.value.match(validNames);
if (match !== null) {
addons[currentHeader].files[match[1]] = node.value;
}
}
});
await Promise.all(
Object.keys(addons).flatMap(
(header) => verifyFiles(addons[header].files, header),
));
function verifyFiles(files, blockName) {
const fileNames = Object.keys(files);
// Must have a .cc and a .js to be a valid test.
if (!fileNames.some((name) => name.endsWith('.cc')) ||
!fileNames.some((name) => name.endsWith('.js'))) {
return [];
}
blockName = blockName.toLowerCase().replace(/\s/g, '_').replace(/\W/g, '');
const dir = new URL(
`./${String(++id).padStart(2, '0')}_${blockName}/`,
verifyDir,
);
files = fileNames.map((name) => {
if (name === 'test.js') {
files[name] = `'use strict';
const common = require('../../common');
${files[name].replace(
"'./build/Release/addon'",
// eslint-disable-next-line no-template-curly-in-string
'`./build/${common.buildType}/addon`')}
`;
}
return {
content: files[name],
name,
url: new URL(`./${name}`, dir),
};
});
files.push({
url: new URL('./binding.gyp', dir),
content: JSON.stringify({
targets: [
{
target_name: 'addon',
sources: files.map(({ name }) => name),
includes: ['../common.gypi'],
},
],
}),
});
const dirCreation = mkdir(dir);
return files.map(({ url, content }) =>
dirCreation.then(() => writeFile(url, content)));
}