Commit d90d6baaba4 for nodejs

commit d90d6baaba44e75a78c6ce4467b1dd8c6f49d967
Author: Aviv Keller <me@aviv.sh>
Date:   Mon Nov 30 16:31:13 2026 -0500

    doc: move to new json generator

    Signed-off-by: avivkeller <me@aviv.sh>
    PR-URL: https://github.com/nodejs/node/pull/66248
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
    Reviewed-By: Claudio Wunder <cwunder@gnome.org>
    Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>

diff --git a/test/doctool/test-doc-api-json.mjs b/test/doctool/test-doc-api-json.mjs
index 2e15173bdc2..0f8cafbbfb0 100644
--- a/test/doctool/test-doc-api-json.mjs
+++ b/test/doctool/test-doc-api-json.mjs
@@ -12,20 +12,83 @@ if (common.isWindows) {
   common.skip('`make doc` does not run on Windows');
 }

-function validateModule(module) {
-  assert.strictEqual(typeof module, 'object');
-  assert.strictEqual(module.type, 'module');
-  assert.ok(module.name);
-  assert.ok(module.textRaw);
+const entryKeys = [
+  'title',
+  'stability',
+  'added',
+  'deprecated',
+  'removed',
+  'napiVersion',
+  'changes',
+  'description',
+  'summary',
+  'examples',
+];
+
+const documentKeys = new Set([
+  '$schema',
+  'id',
+  'path',
+  'type',
+  'module',
+  'introducedIn',
+  'sourceLink',
+  'children',
+  ...entryKeys,
+]);
+
+const documentTypes = new Set(['module', 'misc', 'global']);
+
+const nodeKeys = ['kind', 'id', 'name', 'scope', 'overloadOf', 'children', ...entryKeys];
+
+// The further keys of a heading, by `kind`.
+const kindKeys = {
+  __proto__: null,
+  section: [],
+  class: ['extends'],
+  constructor: ['signature'],
+  method: ['signature'],
+  staticMethod: ['signature'],
+  property: ['type', 'default'],
+  event: ['parameters'],
+};
+
+const isStringOrNull = (value) => value === null || typeof value === 'string';
+
+function validateVersions(versions) {
+  assert.ok(Array.isArray(versions));
+  for (const version of versions) assert.strictEqual(typeof version, 'string');
+}
+
+function validateType(type) {
+  if (type === null) return;
+  assert.strictEqual(typeof type.text, 'string');
+  assert.ok(Array.isArray(type.links));
+  for (const link of type.links) {
+    assert.strictEqual(typeof link.name, 'string');
+    assert.strictEqual(typeof link.href, 'string');
+    assert.strictEqual(type.text.slice(link.start, link.end), link.name);
+  }
 }

-function validateMisc(misc) {
-  assert.strictEqual(typeof misc, 'object');
-  assert.strictEqual(misc.type, 'misc');
-  assert.ok(misc.name);
-  assert.strictEqual(typeof misc.name, 'string');
-  assert.ok(misc.textRaw);
-  assert.strictEqual(typeof misc.textRaw, 'string');
+function validateParameter(parameter) {
+  assert.strictEqual(typeof parameter.name, 'string');
+  validateType(parameter.type);
+  assert.strictEqual(typeof parameter.description, 'string');
+  assert.ok(isStringOrNull(parameter.default));
+  assert.strictEqual(typeof parameter.optional, 'boolean');
+  assert.strictEqual(typeof parameter.rest, 'boolean');
+  assert.ok(Array.isArray(parameter.properties));
+  parameter.properties.forEach(validateParameter);
+}
+
+function validateSignature(signature) {
+  assert.ok(Array.isArray(signature.parameters));
+  signature.parameters.forEach(validateParameter);
+  if (signature.returns !== null) {
+    validateType(signature.returns.type);
+    assert.strictEqual(typeof signature.returns.description, 'string');
+  }
 }

 // Counts of `deprecated` and `removed` metadata found in the current file's
@@ -35,6 +98,95 @@ let numberOfRemovedAPIs = 0;
 let totalDeprecatedSections = 0;
 let totalRemovedAPIs = 0;

+function validateEntry(entry) {
+  assert.strictEqual(typeof entry.title, 'string');
+  assert.ok(entry.title);
+
+  if (entry.stability !== null) {
+    assert.match(entry.stability.index, /^[0-5](\.[0-9])?$/);
+    assert.strictEqual(typeof entry.stability.description, 'string');
+  }
+
+  validateVersions(entry.added);
+  validateVersions(entry.deprecated);
+  validateVersions(entry.removed);
+  if (entry.deprecated.length) numberOfDeprecatedSections++;
+  if (entry.removed.length) numberOfRemovedAPIs++;
+
+  assert.ok(Array.isArray(entry.napiVersion));
+  for (const napiVersion of entry.napiVersion) assert.ok(Number(napiVersion));
+
+  assert.ok(Array.isArray(entry.changes));
+  for (const change of entry.changes) {
+    validateVersions(change.versions);
+    assert.ok(isStringOrNull(change.prUrl));
+    assert.ok(isStringOrNull(change.commit));
+    assert.strictEqual(typeof change.description, 'string');
+  }
+
+  assert.strictEqual(typeof entry.description, 'string');
+  assert.strictEqual(typeof entry.summary, 'string');
+
+  assert.ok(Array.isArray(entry.examples));
+  for (const example of entry.examples) {
+    assert.ok(isStringOrNull(example.language));
+    assert.ok(isStringOrNull(example.displayName));
+    assert.strictEqual(typeof example.code, 'string');
+  }
+}
+
+function validateNode(node, ids) {
+  assert.ok(Object.hasOwn(kindKeys, node.kind), `Unknown kind: ${node.kind}`);
+  assert.deepStrictEqual(
+    new Set(Object.keys(node)),
+    new Set([...nodeKeys, ...kindKeys[node.kind]]),
+    `Unexpected keys in the ${node.kind} ${node.id}`,
+  );
+
+  assert.strictEqual(typeof node.id, 'string');
+  assert.ok(!ids.has(node.id), `Duplicate id: ${node.id}`);
+  ids.add(node.id);
+  assert.strictEqual(typeof node.name, 'string');
+  assert.ok(['module', 'global'].includes(node.scope));
+  assert.ok(isStringOrNull(node.overloadOf));
+
+  validateEntry(node);
+
+  switch (node.kind) {
+    case 'class':
+      validateType(node.extends);
+      break;
+    case 'constructor':
+    case 'method':
+    case 'staticMethod':
+      validateSignature(node.signature);
+      break;
+    case 'property':
+      validateType(node.type);
+      assert.ok(isStringOrNull(node.default));
+      break;
+    case 'event':
+      assert.ok(Array.isArray(node.parameters));
+      node.parameters.forEach(validateParameter);
+      break;
+  }
+
+  validateChildren(node, ids);
+}
+
+function validateChildren(parent, ids) {
+  assert.ok(Array.isArray(parent.children));
+  for (const child of parent.children) validateNode(child, ids);
+}
+
+// Collects every node of a document, to resolve `overloadOf` against.
+function* allNodes(parent) {
+  for (const child of parent.children) {
+    yield child;
+    yield* allNodes(child);
+  }
+}
+
 // Counts the YAML metadata blocks in a Markdown source file that declare
 // `deprecated` or `removed`, so the JSON output can be checked against them.
 const yamlBlockRe = /<!--\s*YAML\r?\n([\s\S]*?)-->/g;
@@ -48,93 +200,14 @@ function countSourceMeta(markdown) {
   return { deprecated, removed };
 }

-const metaExpectedKeys = new Set([
-  'added',
-  'changes',
-  'deprecated',
-  'napiVersion',
-  'removed',
-]);
+const outDir = new URL('../../out/doc/api/', import.meta.url);
+const documents = new Map();

-function validateMeta(meta) {
-  assert.partialDeepStrictEqual(metaExpectedKeys, new Set(Object.keys(meta)));
-  assert.ok(!Object.hasOwn(meta, 'added') || Array.isArray(meta.added) || typeof meta.added === 'string');
-  if (meta.deprecated) {
-    numberOfDeprecatedSections++;
-    assert.ok(Array.isArray(meta.deprecated) || typeof meta.deprecated === 'string');
-  }
-  if (meta.removed) {
-    numberOfRemovedAPIs++;
-    assert.ok(Array.isArray(meta.removed) || typeof meta.removed === 'string');
-  }
-
-  assert.ok(!Object.hasOwn(meta, 'napiVersion') || Number(meta.napiVersion));
-  assert.ok(Array.isArray(meta.changes));
-}
-
-function findAllKeys(obj, allKeys = new Set()) {
-  for (const [key, value] of Object.entries(obj)) {
-    if (Number.isNaN(Number(key))) allKeys.add(key);
-    if (typeof value === 'object') findAllKeys(value, allKeys);
-
-    if (key === 'miscs') {
-      assert.ok(Array.isArray(value));
-      assert.ok(value.length);
-      value.forEach(validateMisc);
-    } else if (key === 'modules') {
-      assert.ok(Array.isArray(value));
-      assert.ok(value.length);
-      value.forEach(validateModule);
-    } else if (key === 'meta') {
-      validateMeta(value);
-    }
-  }
-  return allKeys;
-}
-
-const allExpectedKeys = new Set([
-  'added',
-  'changes',
-  'classes',
-  'classMethods',
-  'commit',
-  'ctors',
-  'default',
-  'deprecated',
-  'desc',
-  'description',
-  'displayName',
-  'events',
-  'examples',
-  'globals',
-  'introduced_in',
-  'meta',
-  'methods',
-  'miscs',
-  'modules',
-  'name',
-  'napiVersion',
-  'optional',
-  'options',
-  'params',
-  'pr-url',
-  'properties',
-  'removed',
-  'return',
-  'shortDesc',
-  'signatures',
-  'source',
-  'stability',
-  'stabilityText',
-  'textRaw',
-  'type',
-  'version',
-]);
-
-for await (const dirent of await fs.opendir(new URL('../../out/doc/api/', import.meta.url))) {
+for await (const dirent of await fs.opendir(outDir)) {
   if (!dirent.name.endsWith('.md')) continue;

-  const jsonPath = path.join(dirent.parentPath, dirent.name.slice(0, -2) + 'json');
+  const name = dirent.name.slice(0, -3);
+  const jsonPath = path.join(dirent.parentPath, `${name}.json`);
   const expectedSource = `doc/api/${dirent.name}`;
   if (dirent.name === 'quic.md') {
     assert.ok(!existsSync(jsonPath)); // QUIC documentation is not public yet
@@ -149,32 +222,29 @@ for await (const dirent of await fs.opendir(new URL('../../out/doc/api/', import
   assert.strictEqual(fileContent.split('\n', 3).length, 3);

   const json = JSON.parse(fileContent);
+  documents.set(name, json);

-  assert.strictEqual(json.type, 'module');
-  assert.strictEqual(json.source, expectedSource);
-  if (dirent.name !== 'index.md') {
-    assert.ok(json.introduced_in || Object.values(json).at(-1)?.[0].introduced_in);
+  assert.deepStrictEqual(new Set(Object.keys(json)), documentKeys);
+  assert.match(json.$schema, /\/api-doc\/\d+\.\d+\.\d+\.json$/);
+  assert.strictEqual(json.id, name);
+  assert.strictEqual(json.path, `/${name}`);
+  assert.ok(documentTypes.has(json.type), `Unknown type: ${json.type}`);
+  assert.ok(isStringOrNull(json.module));
+  assert.strictEqual(typeof json.introducedIn, 'string');
+  if (json.sourceLink !== null) {
+    assert.ok(existsSync(new URL(`../../${json.sourceLink.path}`, import.meta.url)),
+              `${json.sourceLink.path} does not exist`);
   }
-  assert.deepStrictEqual(Object.keys(json), ['type', 'source', ...({
-    'addons.md': ['introduced_in', 'miscs'],
-    'cli.md': ['introduced_in', 'miscs'],
-    'debugger.md': ['introduced_in', 'stability', 'stabilityText', 'miscs'],
-    'deprecations.md': ['introduced_in', 'miscs'],
-    'documentation.md': ['introduced_in', 'miscs'],
-    'errors.md': ['introduced_in', 'classes', 'miscs'],
-    'esm.md': ['introduced_in', 'meta', 'stability', 'stabilityText', 'properties', 'miscs'],
-    'globals.md': ['introduced_in', 'stability', 'stabilityText', 'classes', 'methods', 'miscs'],
-    'index.md': [],
-    'intl.md': ['introduced_in', 'miscs'],
-    'n-api.md': ['introduced_in', 'stability', 'stabilityText', 'miscs'],
-    'packages.md': ['introduced_in', 'meta', 'miscs'],
-    'process.md': ['globals'],
-    'report.md': ['introduced_in', 'meta', 'stability', 'stabilityText', 'miscs'],
-  }[dirent.name] ?? ['modules'])]);

   numberOfDeprecatedSections = 0;
   numberOfRemovedAPIs = 0;
-  assert.partialDeepStrictEqual(allExpectedKeys, findAllKeys(json));
+  validateEntry(json);
+  const ids = new Set();
+  validateChildren(json, ids);
+  for (const node of allNodes(json)) {
+    assert.ok(node.overloadOf === null || ids.has(node.overloadOf),
+              `${node.id} is an overload of a missing ${node.overloadOf}`);
+  }

   const markdown = await fs.readFile(
     new URL(`../../${expectedSource}`, import.meta.url), 'utf8');
@@ -189,5 +259,15 @@ for await (const dirent of await fs.opendir(new URL('../../out/doc/api/', import

 // Guard against the source scan and the JSON output both silently finding
 // nothing (e.g. if the YAML metadata format changes).
+assert.ok(documents.size > 0);
 assert.ok(totalDeprecatedSections > 0);
 assert.ok(totalRemovedAPIs > 0);
+
+// `all.json` bundles every document.
+const all = JSON.parse(await fs.readFile(new URL('all.json', outDir), 'utf8'));
+assert.deepStrictEqual(Object.keys(all).sort(), ['$schema', 'documents']);
+assert.match(all.$schema, /\/api-doc-all\/\d+\.\d+\.\d+\.json$/);
+assert.strictEqual(all.documents.length, documents.size);
+for (const document of all.documents) {
+  assert.deepStrictEqual(document, documents.get(document.id));
+}
diff --git a/tools/doc/package-lock.json b/tools/doc/package-lock.json
index 4422100f5f8..d50279bc7ad 100644
--- a/tools/doc/package-lock.json
+++ b/tools/doc/package-lock.json
@@ -8,8 +8,7 @@
       "dependencies": {
         "@doc-kit/cli": "1.1.1",
         "@doc-kit/generator-react": "0.5.2",
-        "@node-core/doc-kit": "2.0.7",
-        "@node-core/doc-kit-legacy": "1.1.2"
+        "@node-core/doc-kit": "2.0.7"
       }
     },
     "node_modules/@11ty/is-land": {
@@ -587,21 +586,6 @@
         "unist-util-visit": "^5.1.0"
       }
     },
-    "node_modules/@node-core/doc-kit-legacy": {
-      "version": "1.1.2",
-      "resolved": "https://registry.npmjs.org/@node-core/doc-kit-legacy/-/doc-kit-legacy-1.1.2.tgz",
-      "integrity": "sha512-RgvvU62Y1+j9CK4H4bkZBcuT+HVsc+BjJ2sfca09qloB3GaSH+Qc4aUwCAX2OyswLVUZwtVtg63UXqJpHYgcpA==",
-      "license": "MIT",
-      "dependencies": {
-        "@doc-kit/core": "1.3.1",
-        "hastscript": "^9.0.1",
-        "rehype-stringify": "^10.0.1",
-        "remark-parse": "^11.0.0",
-        "remark-rehype": "^11.1.2",
-        "unist-builder": "^4.0.0",
-        "unist-util-visit": "^5.1.0"
-      }
-    },
     "node_modules/@node-core/rehype-shiki": {
       "version": "1.5.1",
       "resolved": "https://registry.npmjs.org/@node-core/rehype-shiki/-/rehype-shiki-1.5.1.tgz",
diff --git a/tools/doc/package.json b/tools/doc/package.json
index 9b291286315..ef7518b9300 100644
--- a/tools/doc/package.json
+++ b/tools/doc/package.json
@@ -4,7 +4,6 @@
   "dependencies": {
     "@doc-kit/cli": "1.1.1",
     "@doc-kit/generator-react": "0.5.2",
-    "@node-core/doc-kit": "2.0.7",
-    "@node-core/doc-kit-legacy": "1.1.2"
+    "@node-core/doc-kit": "2.0.7"
   }
 }
diff --git a/tools/doc/web.doc-kit.config.mjs b/tools/doc/web.doc-kit.config.mjs
index fd5b2facd57..a5b3d0e4379 100644
--- a/tools/doc/web.doc-kit.config.mjs
+++ b/tools/doc/web.doc-kit.config.mjs
@@ -15,7 +15,7 @@ export default {
   'extends': '@node-core/doc-kit/config',

   'target': [
-    'legacy-json-all',
+    'json-all',
     'section-pages',
     'llms-txt',
   ],