Skip to content

Commit 5cf8968

Browse files
authored
fix(legacy-json): preserve source subdirectories in output paths (#841)
1 parent b96e4e5 commit 5cf8968

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@node-core/doc-kit",
33
"type": "module",
4-
"version": "1.3.9",
4+
"version": "1.3.10",
55
"repository": {
66
"type": "git",
77
"url": "git+https://github.com/nodejs/doc-kit.git"

src/generators/legacy-json/generate.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3-
import { writeFile } from 'node:fs/promises';
43
import { join } from 'node:path';
54

65
import { createSectionBuilder } from './utils/buildSection.mjs';
76
import getConfig from '../../utils/configuration/index.mjs';
7+
import { writeFile, withExt } from '../../utils/file.mjs';
88
import { groupNodesByModule, legacyToJSON } from '../../utils/generators.mjs';
99

1010
const buildSection = createSectionBuilder();
@@ -42,6 +42,10 @@ export async function* generate(input, worker) {
4242

4343
const headNodes = input.filter(node => node.heading.depth === 1);
4444

45+
// Map each section's `api` slug back to its source path so the output keeps
46+
// the input directory structure instead of flattening into the root.
47+
const pathByApi = new Map(headNodes.map(({ api, path }) => [api, path]));
48+
4549
// Create sliced input: each item contains head + its module's entries
4650
// This avoids sending all 4900+ entries to every worker
4751
const entries = headNodes.map(head => ({
@@ -52,7 +56,10 @@ export async function* generate(input, worker) {
5256
for await (const chunkResult of worker.stream(entries)) {
5357
if (config.output) {
5458
for (const section of chunkResult) {
55-
const out = join(config.output, `${section.api}.json`);
59+
const out = join(
60+
config.output,
61+
withExt(pathByApi.get(section.api), 'json')
62+
);
5663

5764
await writeFile(
5865
out,

0 commit comments

Comments
 (0)